本文整理匯總了Python中receiver.Receiver.start方法的典型用法代碼示例。如果您正苦於以下問題:Python Receiver.start方法的具體用法?Python Receiver.start怎麽用?Python Receiver.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類receiver.Receiver
的用法示例。
在下文中一共展示了Receiver.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: emulate
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def emulate(args):
'''
Starts the Sender/Receiver process threads, sleeps for
args.RUNTIME, and terminates both threads. Returns a tuple of
lists: (s_log, r_log), where s_log is sender's log and r_log is
receiver's log.
'''
args.SENDER_TIMEOUT = float(args.SENDER_TIMEOUT)
args.RUNTIME = float(args.RUNTIME)
assert args.SENDER_TIMEOUT > 0
assert args.RUNTIME > 0
s = Sender(args.SENDER_TIMEOUT)
r = Receiver()
s.set_remote_endpoint(r)
r.set_remote_endpoint(s)
r.daemon = True
s.daemon = True
# Start the sender process.
s.start()
r.start()
try:
time.sleep(args.RUNTIME)
except KeyboardInterrupt:
print "Interrupted, terminating."
# We have to be careful with terminating the two threads, as they
# can only exit in specific states, and we can cause a deadlock.
# First, we terminate the sender, and wait for it to finish. Once
# this happens, we know that the receiver is in an ok terminal
# state, so we terminate it right after.
s.terminate()
s.join()
r.terminate()
r.join()
#s.log.append((([0,0], "S-TERM")))
#r.log.append((([0,0], "R-TERM")))
# At this point, the sender is not generating any more
# messages. But, we might have some oustanding messages in
# receiver's queue. So, process these, if any:
while not r.rx_queue.empty():
# Receive msg and generate any outstanding acks.
r.transition()
r.transition()
r.transition()
# Consume any outstanding acks on the sender's side.
s.consume_acks()
return (s.log, r.log)
示例2: ncd_loop
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def ncd_loop(doInit, dlThreadNum):
ndutil.setTimezone()
#read config
cnfManager = CnfManager()
cnfManager.load('./ndc.cnf')
cnfData = cnfManager.getCnfData()
#check dirs
ndutil.enableDir(cnfData['dirWorking'])
ndutil.enableDir(cnfData['dirStore'])
#ndlcom
logger = Logger('nDroid-Crawler', cnfData['ndlComHost'], cnfData['ndlComPort'])
logger.logger('Initiating')
dbManager = DbManager(cnfData['dbHost'], cnfData['dbUser'], cnfData['dbPass'], cnfData['dbName'])
if doInit:
dbManager.create_table()
os.system('rm -f %s/*' % cnfData['dirWorking'])
os.system('rm -f %s/*' % cnfData['dirStore'])
#logger.logger('Customizing Spiders')
#spiderGenerator = SpiderGenerator('template', 'spider/spiders')
#for spider in cnfData['spiders']:
# spiderGenerator.gen_spider(spider, cnfData[spider]['startPage'], cnfData[spider]['stopPage'])
rpQueue = Queue()
pdQueue = Queue()
dpQueue = Queue()
pdLock = threading.Lock()
rpcMonitor = RpcMonitor(logger, cnfData['rpcPort'], cnfData['rpcAuth'], 'RpcMonitor')
rpcMonitor.setGlobalInfo(ndutil.getCurrentTimeStr(), 'Standalone', dlThreadNum)
rpcMonitor.setDownloadTotal(pdQueue.qsize())
rpcMonitor.setPdQueueSize(pdQueue.qsize())
botScheduler = BotScheduler(logger, rpcMonitor, cnfData['spiders'], cnfData['spiderCnfs'], 'BotScheduler')
receiver = Receiver(logger, rpcMonitor, rpQueue, cnfData['receiverPort'], 'Receiver')
preProcessor = PreProcessor(logger, rpcMonitor, rpQueue, pdQueue, pdLock, dbManager, 'PreProcessor')
downloader = Downloader([logger, rpcMonitor, pdQueue, dpQueue, pdLock, dlThreadNum, cnfData['dirWorking']], 'Downloader')
processor = Processor(logger, rpcMonitor, dpQueue, pdLock, pdQueue, dbManager, cnfData['dirWorking'], cnfData['dirStore'], 'Processor')
logger.logger('Starting Threads')
rpcMonitor.start()
botScheduler.start()
receiver.start()
preProcessor.start()
downloader.start()
processor.start()
processor.join()
downloader.join()
preProcessor.join()
receiver.join()
botScheduler.join()
rpcMonitor.join()
示例3: start_recvers
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def start_recvers(self):
for port in self.cl_port_list:
addr = (self.cl_ip, port)
recver = Receiver(in_queue = self.queue_torecvers,
laddr = addr,
proto = self.proto,
rx_type = self.rx_type,
file_url = 'rx_over_%s.dat' % port,
logto = self.logto )
recver.start()
self.recver_thread_list.append(recver)
示例4: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def run(self):
self.done = Event()
while not self.done.isSet():
print('Waiting for clients')
client_sock, client_info = self.server_sock.accept()
r = Receiver(self, client_sock, client_info)
r.daemon = True
r.start()
self.server_sock.close()
print('The server socket has been closed')
示例5: main
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def main():
global indexer, uploader, sender, receiver, downloader
setup_signals()
logging.info("Asink client started at %s" %
(time.strftime("%a, %d %b %Y %X GMT", time.gmtime())))
#create all threads which will be used to process events
indexer = Indexer()
uploader = Uploader()
sender = Sender()
receiver = Receiver()
downloader = Downloader()
#create and set up queues which are used to pass events between threads
uploader_queue = Queue()
indexer.uploader_queue = uploader_queue
uploader.queue = uploader_queue
#set on watcher when initialized
sender_queue = Queue()
uploader.sender_queue = sender_queue
sender.queue = sender_queue
downloader_queue = Queue()
receiver.downloader_queue = downloader_queue
downloader.queue = downloader_queue
#setup storage provider
storage = setup_storage()
uploader.storage = storage.clone()
downloader.storage = storage
#start all threads
watcher.start_watching(uploader_queue)
indexer.start()
uploader.start()
sender.start()
receiver.start()
downloader.start()
#sleep until signaled, which will call sig_handler
while True:
time.sleep(86400) #= 24 hours just for fun
示例6: welcome_s
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def welcome_s(self, data_):
sch_req_id = data_['sch_req_id']
stpdst = data_['tp_dst']
qtorecver = Queue.Queue(0)
qfromrecver = Queue.Queue(0)
laddr = (self.cl_ip, int(stpdst))
recver = Receiver(in_queue = qtorecver,
out_queue = qfromrecver,
laddr = laddr,
proto = self.proto,
rx_type = 'kstardata',
file_url = 'kstardata_%s.dat' % stpdst,
logto = self.logto )
recver.start()
#
self.sinfo_dict[sch_req_id] = {'tp_dst': stpdst,
'qtorecver': qtorecver,
'qfromrecver': qfromrecver }
logging.info('welcome_s:: welcome sinfo=\n%s', pprint.pformat(self.sinfo_dict[sch_req_id]))
threading.Thread(target = self.waitfor_couplingtoend,
kwargs = {'sch_req_id': sch_req_id} ).start()
示例7: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def run(self):
sleep_time = 0
while True:
if (os.getppid() != self.ppid):
logger.info('parent exited. aborting.')
break
try:
self.rep_ip = self._replication_interface()
break
except:
time.sleep(1)
sleep_time = sleep_time + 1
if (sleep_time % 30 == 0):
msg = ('Failed to get replication interface for last %d'
' seconds' % sleep_time)
logger.info('failed to get replication interface')
ctx = zmq.Context()
#fs diffs are sent via this publisher.
rep_pub = ctx.socket(zmq.PUB)
rep_pub.bind('tcp://%s:%d' % (self.rep_ip, self.data_port))
#synchronization messages are received in this pull socket
meta_pull = ctx.socket(zmq.PULL)
meta_pull.RCVTIMEO = 100
meta_pull.bind('tcp://%s:%d' % (self.rep_ip, self.meta_port))
total_sleep = 0
while True:
if (os.getppid() != self.ppid):
logger.info('parent exited. aborting.')
break
while(not self.pubq.empty()):
msg = self.pubq.get()
rep_pub.send(msg)
#check for any recv's coming
try:
self.recv_meta = meta_pull.recv_json()
snap_id = self.recv_meta['id']
if (self.recv_meta['msg'] == 'begin'):
logger.info('begin received. meta: %s' % self.recv_meta)
rw = Receiver(self.recv_meta, Queue())
self.receivers[snap_id] = rw
rw.start()
elif (self.recv_meta['msg'] == 'begin_ok'):
self.senders[snap_id].q.put('send')
elif (self.recv_meta['msg'] == 'receive_ok' or
self.recv_meta['msg'] == 'receive_error'):
self.senders[snap_id].q.put(self.recv_meta['msg'])
except zmq.error.Again:
pass
self._prune_workers((self.receivers, self.senders))
if (total_sleep >= 60 and len(self.senders) < 50):
logger.info('scanning for replicas')
for r in Replica.objects.filter(enabled=True):
rt = ReplicaTrail.objects.filter(replica=r).order_by('-snapshot_created')
now = datetime.utcnow().replace(second=0,
microsecond=0,
tzinfo=utc)
sw = None
snap_name = ('%s_replica_snap' % r.share)
if (len(rt) == 0):
snap_name = ('%s_1' % snap_name)
sw = Sender(r, self.rep_ip, self.pubq, Queue(),
snap_name)
elif (rt[0].status == 'succeeded' and
(now - rt[0].end_ts).total_seconds() >
r.frequency):
snap_name = ('%s_%d' % (snap_name, rt[0].id + 1))
sw = Sender(r, self.rep_ip, self.pubq, Queue(),
snap_name, rt[0])
else:
continue
snap_id = ('%s_%s_%s_%s' %
(self.rep_ip, r.pool, r.share, snap_name))
self.senders[snap_id] = sw
sw.daemon = True
sw.start()
total_sleep = 0
time.sleep(1)
total_sleep = total_sleep + 1
示例8: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def run(self):
self.law = APIWrapper()
try:
so = Service.objects.get(name='replication')
config_d = json.loads(so.config)
self.listener_port = int(config_d['listener_port'])
nco = NetworkConnection.objects.get(
name=config_d['network_interface'])
self.listener_interface = nco.ipaddr
except NetworkConnection.DoesNotExist:
self.listener_interface = '0.0.0.0'
except Exception as e:
msg = ('Failed to fetch network interface for Listner/Broker. '
'Exception: %s' % e.__str__())
return logger.error(msg)
try:
self.uuid = Appliance.objects.get(current_appliance=True).uuid
except Exception as e:
msg = ('Failed to get uuid of current appliance. Aborting. '
'Exception: %s' % e.__str__())
return logger.error(msg)
ctx = zmq.Context()
frontend = ctx.socket(zmq.ROUTER)
frontend.set_hwm(10)
frontend.bind('tcp://%s:%d'
% (self.listener_interface, self.listener_port))
backend = ctx.socket(zmq.ROUTER)
backend.bind('ipc://%s' % settings.REPLICATION.get('ipc_socket'))
poller = zmq.Poller()
poller.register(frontend, zmq.POLLIN)
poller.register(backend, zmq.POLLIN)
self.local_receivers = {}
iterations = 10
poll_interval = 6000 # 6 seconds
msg_count = 0
while True:
# This loop may still continue even if replication service
# is terminated, as long as data is coming in.
socks = dict(poller.poll(timeout=poll_interval))
if (frontend in socks and socks[frontend] == zmq.POLLIN):
address, command, msg = frontend.recv_multipart()
if (address not in self.remote_senders):
self.remote_senders[address] = 1
else:
self.remote_senders[address] += 1
msg_count += 1
if (msg_count == 1000):
msg_count = 0
for rs, count in self.remote_senders.items():
logger.debug('Active Receiver: %s. Messages processed:'
'%d' % (rs, count))
if (command == 'sender-ready'):
logger.debug('initial greeting from %s' % address)
# Start a new receiver and send the appropriate response
try:
start_nr = True
if (address in self.local_receivers):
start_nr = False
ecode = self.local_receivers[address].exitcode
if (ecode is not None):
del self.local_receivers[address]
logger.debug('Receiver(%s) exited. exitcode: '
'%s. Forcing removal from broker '
'list.' % (address, ecode))
start_nr = True
else:
msg = ('Receiver(%s) already exists. '
'Will not start a new one.' %
address)
logger.error(msg)
# @todo: There may be a different way to handle
# this. For example, we can pass the message to
# the active receiver and factor into it's
# retry/robust logic. But that is for later.
frontend.send_multipart(
[address, 'receiver-init-error', msg])
if (start_nr):
nr = Receiver(address, msg)
nr.daemon = True
nr.start()
logger.debug('New Receiver(%s) started.' % address)
self.local_receivers[address] = nr
continue
except Exception as e:
msg = ('Exception while starting the '
'new receiver for %s: %s'
% (address, e.__str__()))
logger.error(msg)
frontend.send_multipart(
[address, 'receiver-init-error', msg])
else:
# do we hit hwm? is the dealer still connected?
backend.send_multipart([address, command, msg])
#.........這裏部分代碼省略.........
示例9: __init__
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
#.........這裏部分代碼省略.........
self._show_disarmed(self.root)
self._show_disarmed(self.pane1)
self._show_disarmed(self.pane2)
def scheduleTask(self, delay_msec, task):
self.root.after(delay_msec, task)
def _add_pane(self):
pane = PanedWindow(self.frame, bg=BACKGROUND_COLOR)
pane.pack(fill=BOTH, expand=1)
return pane
def _add_button(self, label, parent, callback, disabled=True):
button = Button(parent, text=label, command=callback)
button.pack(side=LEFT)
button.config(state = 'disabled' if disabled else 'normal')
return button
# Callback for Setup button
def _setup_callback(self):
self._clear()
self.motors.stop()
self.receiver.stop()
self.messages.stop()
#self.maps.stop()
self.parser.set_ATTITUDE_Handler(self._handle_attitude)
self.setup.start()
def _start(self):
self.parser.set_ATTITUDE_Handler(self._handle_attitude)
self._send_attitude_request()
self.setup.start()
self.parser.set_RC_Handler(self._handle_rc)
self._send_rc_request()
# Sends Attitude request to FC
def _send_attitude_request(self):
self.comms.send_request(self.attitude_request)
# Sends RC request to FC
def _send_rc_request(self):
self.comms.send_request(self.rc_request)
# Callback for Motors button
def _motors_button_callback(self):
self._clear()
self.setup.stop()
self.parser.set_ATTITUDE_Handler(self._handle_attitude)
self.receiver.stop()
self.messages.stop()
#self.maps.stop()
self.motors.start()
示例10: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def run(self):
while True:
try:
self.rep_ip = self._replication_interface()
self.uuid = self._my_uuid()
break
except:
msg = "Failed to get replication interface or uuid. " "Aborting."
return logger.error(msg)
ctx = zmq.Context()
# fs diffs are sent via this publisher.
rep_pub = ctx.socket(zmq.PUB)
rep_pub.bind("tcp://%s:%d" % (self.rep_ip, self.data_port))
# synchronization messages are received in this pull socket
meta_pull = ctx.socket(zmq.PULL)
meta_pull.RCVTIMEO = 100
meta_pull.bind("tcp://%s:%d" % (self.rep_ip, self.meta_port))
total_sleep = 0
while True:
if os.getppid() != self.ppid:
logger.error("Parent exited. Aborting.")
break
while not self.pubq.empty():
msg = self.pubq.get()
rep_pub.send(msg)
# check for any recv's coming
num_msgs = 0
while num_msgs < 1000:
try:
self.recv_meta = meta_pull.recv_json()
num_msgs = num_msgs + 1
snap_id = self.recv_meta["id"]
if self.recv_meta["msg"] == "begin":
rw = Receiver(self.recv_meta)
self.receivers[snap_id] = rw
rw.start()
elif snap_id not in self.senders:
logger.error("Unknown snap_id(%s) received. Ignoring" % snap_id)
else:
self.senders[snap_id].q.put(self.recv_meta)
except zmq.error.Again:
break
self._prune_workers((self.receivers, self.senders))
if int(time.time()) - self.prune_time > 3600:
self.prune_time = int(time.time())
for rs in ReplicaShare.objects.all():
prune_receive_trail(rs.id, logger)
for r in Replica.objects.all():
prune_replica_trail(r.id, logger)
if total_sleep >= 60 and len(self.senders) < 50:
try:
for r in get_replicas(logger):
rt = get_replica_trail(r.id, logger)
now = datetime.utcnow().replace(second=0, microsecond=0, tzinfo=utc)
sw = None
snap_name = "replication"
rt2 = ReplicaTrail.objects.filter().order_by("-id")
if len(rt2) != 0:
snap_name = "%s_%d" % (snap_name, rt2[0].id + 1)
else:
snap_name = "%s_1" % snap_name
snap_id = "%s_%s_%s_%s" % (self.uuid, r.pool, r.share, snap_name)
if len(rt) == 0:
logger.debug("new sender for snap: %s" % snap_id)
sw = Sender(
r,
self.rep_ip,
self.pubq,
Queue(),
snap_name,
self.meta_port,
self.data_port,
r.meta_port,
self.uuid,
snap_id,
)
elif rt[0].status == "succeeded":
if (now - rt[0].end_ts).total_seconds() > (r.frequency * 60):
logger.debug("incremental sender for snap: %s" % snap_id)
sw = Sender(
r,
self.rep_ip,
self.pubq,
Queue(),
snap_name,
self.meta_port,
self.data_port,
r.meta_port,
self.uuid,
snap_id,
rt[0],
#.........這裏部分代碼省略.........
示例11: VpnServer
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
class VpnServer(object):
def __init__(self, port, shared_key, connected_callback, broken_conn_callback,
debug_continue, debug, app):
self.port = port
self.shared_key = shared_key
self.connected_callback = connected_callback
self.broken_conn_callback = broken_conn_callback
self.send_queue = Queue()
self.receive_queue = Queue()
self.authenticated = False
self.debug_continue = debug_continue
self.debug = debug
self.waiting = True
self.sender = None
self.receiver = None
self.is_server = True
self.sessionkey=''
self.app = app
def setup(self):
try:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
return (-1, "Could not create socket")
try:
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(('', self.port))
Logger.log("Listening for connections...", self.is_server)
self.socket.listen(1)
except socket.error:
return (-1, "Could not bind socket to port " + str(self.port))
return (0, "VPN server set to listen on port " + str(self.port))
def send(self, msg):
if (self.authenticated):
Logger.log("sessionkey: " +self.sessionkey, self.is_server)
emsg = self.auth.encrypt_message(msg, self.auth.get_sessionkey())
self.send_queue.put(emsg)
Logger.log("Put message on send queue: "+ msg, self.is_server)
else:
self.send_queue.put(msg)
Logger.log("Put message on send queue: "+ msg, self.is_server)
def receive(self):
if not self.receive_queue.empty():
msg = self.receive_queue.get()
if (self.authenticated):
msg, valid = self.auth.decrypt_message(msg, self.auth.get_sessionkey())
if valid is False:
return None
Logger.log("Decrypted msg: "+ msg, self.is_server)
return msg
else:
return None
def start(self, callback=None):
self.listener = Listener(self.socket, self.shared_key, self, self.connected_callback, self.app)
self.listener.start()
def bind(self, client_socket):
self.debug_continue.disabled = self.debug
self.sender = Sender(client_socket, self.send_queue, self)
self.receiver = Receiver(client_socket, self.receive_queue, self)
self.sender.start()
self.receiver.start()
def clear_queues(self):
self.receive_queue.queue.clear()
self.send_queue.queue.clear()
def broken_conn(self):
Logger.log("Broken connection", self.is_server)
self.send_queue.queue.clear()
self.receive_queue.queue.clear()
self.sender.close()
self.receiver.close()
self.waiting = True
self.authenticated = False
if (self.listener):
self.listener.broken_conn()
def close(self):
Logger.log("Connection closing", self.is_server)
self.send_queue.queue.clear()
self.receive_queue.queue.clear()
self.listener.close()
self.socket.close()
self.authenticated = False
if self.sender:
self.sender.close()
if self.receiver:
self.receiver.close()
示例12: while
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
if (num_msgs > self.msg_buffer_size):
break
# check for any recv's coming
num_msgs = 0
while (num_msgs < self.msg_buffer_size):
#if we received msg_buffer_size number of messages at once,
#take a break to do other stuff and come back.
try:
self.recv_meta = meta_pull.recv_json()
num_msgs = num_msgs + 1
snap_id = self.recv_meta['id']
if (self.recv_meta['msg'] == 'begin'):
rw = Receiver(self.recv_meta)
self.receivers[snap_id] = rw
rw.start()
elif (snap_id not in self.senders):
logger.error('Unknown snap_id(%s) received. Ignoring'
% snap_id)
else:
self.senders[snap_id].q.put(self.recv_meta)
except zmq.error.Again:
#recv_json throws this exception if nothing is received
#for 100 milliseconds. Break, do other stuff and come back here.
break
self._prune_workers((self.receivers, self.senders))
if (int(time.time()) - self.prune_time > self.trail_prune_interval):
#trail objects keep accumulating and may grow to be quite large.
#so once every trail_prune_interval seconds, deleted the old ones
示例13: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def run(self):
self.listen.listen(15)
while Connector.non_stop:
c, addr = self.listen.accept()
receiver = Receiver(self.listen,c,addr)
receiver.start()
示例14: run
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
def run(self):
while True:
try:
self.rep_ip = self._replication_interface()
self.uuid = self._my_uuid()
break
except:
msg = ('Failed to get replication interface or uuid. '
'Aborting.')
return logger.error(msg)
ctx = zmq.Context()
# fs diffs are sent via this publisher.
rep_pub = ctx.socket(zmq.PUB)
rep_pub.bind('tcp://%s:%d' % (self.rep_ip, self.data_port))
# synchronization messages are received in this pull socket
meta_pull = ctx.socket(zmq.PULL)
meta_pull.RCVTIMEO = 100
meta_pull.bind('tcp://%s:%d' % (self.rep_ip, self.meta_port))
total_sleep = 0
while True:
if (os.getppid() != self.ppid):
logger.error('Parent exited. Aborting.')
break
while(not self.pubq.empty()):
msg = self.pubq.get()
rep_pub.send(msg)
# check for any recv's coming
num_msgs = 0
while (num_msgs < 1000):
try:
self.recv_meta = meta_pull.recv_json()
num_msgs = num_msgs + 1
snap_id = self.recv_meta['id']
if (self.recv_meta['msg'] == 'begin'):
rw = Receiver(self.recv_meta)
self.receivers[snap_id] = rw
rw.start()
elif (snap_id not in self.senders):
logger.error('Unknown snap_id(%s) received. Ignoring'
% snap_id)
else:
self.senders[snap_id].q.put(self.recv_meta)
except zmq.error.Again:
break
self._prune_workers((self.receivers, self.senders))
if (int(time.time()) - self.prune_time > 3600):
self.prune_time = int(time.time())
for rs in ReplicaShare.objects.all():
prune_receive_trail(rs.id, logger)
for r in Replica.objects.all():
prune_replica_trail(r.id, logger)
if (total_sleep >= 60 and len(self.senders) < 50):
try:
for r in get_replicas(logger):
rt = get_replica_trail(r.id, logger)
now = datetime.utcnow().replace(second=0,
microsecond=0,
tzinfo=utc)
sw = None
snap_name = 'replication'
rt2 = ReplicaTrail.objects.filter().order_by('-id')
if (len(rt2) != 0):
snap_name = ('%s_%d' % (snap_name, rt2[0].id + 1))
else:
snap_name = ('%s_1' % snap_name)
snap_id = ('%s_%s_%s_%s' %
(self.uuid, r.pool, r.share, snap_name))
if (len(rt) == 0):
logger.debug('new sender for snap: %s' % snap_id)
sw = Sender(r, self.rep_ip, self.pubq, Queue(),
snap_name, self.meta_port,
self.data_port, r.meta_port, self.uuid,
snap_id)
elif (rt[0].status == 'succeeded'):
if (((now - rt[0].end_ts).total_seconds() >
(r.frequency * 60))):
logger.debug('incremental sender for snap: %s'
% snap_id)
sw = Sender(r, self.rep_ip, self.pubq, Queue(),
snap_name, self.meta_port,
self.data_port, r.meta_port,
self.uuid, snap_id, rt[0])
else:
continue
elif (rt[0].status == 'pending'):
prev_snap_id = ('%s_%s_%s_%s' % (self.uuid,
r.pool, r.share, rt[0].snap_name))
if (prev_snap_id in self.senders):
logger.debug('send process ongoing for snap: '
'%s' % snap_id)
continue
#.........這裏部分代碼省略.........
示例15: exit
# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import start [as 別名]
exit(1)
def printHelp():
print("""
-w - ожидание сеанса измерения скорости
-с [ip] [packet size] [packets count] - измерение скорости с ip, отправка packet count пакетов
по packet size байт каждый
""")
if __name__ == "__main__":
if len(sys.argv) == 1:
printHelp()
else:
argsInfo = parseArgs(sys.argv)
if argsInfo == Mode.help:
printHelp()
try:
if argsInfo[0] == Mode.wait:
receiver = Receiver()
receiver.start()
else:
sender = Sender(destIP=argsInfo[1]["ip"], packetSize=argsInfo[1]["packet_size"],
packetsToSend=argsInfo[1]["packets_count"])
sender.measure()
except Exception as e:
fatalError(e)