本文整理汇总了Python中sender.Sender.daemon方法的典型用法代码示例。如果您正苦于以下问题:Python Sender.daemon方法的具体用法?Python Sender.daemon怎么用?Python Sender.daemon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sender.Sender
的用法示例。
在下文中一共展示了Sender.daemon方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emulate
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import daemon [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: run
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import daemon [as 别名]
#.........这里部分代码省略.........
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
logger.debug('%s not found in senders. Previous '
'sender must have Aborted. Marking '
'it as failed' % prev_snap_id)
msg = ('Sender process Aborted. See logs for '
'more information')
data = {'status': 'failed',
'end_ts': now.strftime(settings.SNAP_TS_FORMAT),
'error': msg,
'send_failed': now, }
update_replica_status(rt[0].id, data, logger)
continue
elif (rt[0].status == 'failed'):
snap_name = rt[0].snap_name
# if num_failed attempts > 10, disable the replica
num_tries = 0
for rto in rt:
if (rto.status != 'failed' or
num_tries >= self.MAX_ATTEMPTS or
rto.end_ts < r.ts):
break
num_tries = num_tries + 1
if (num_tries >= self.MAX_ATTEMPTS):
logger.info('Maximum attempts(%d) reached '
'for snap: %s. Disabling the '
'replica.' %
(self.MAX_ATTEMPTS, snap_id))
disable_replica(r.id, logger)
continue
logger.info('previous backup failed for snap: '
'%s. Starting a new one. Attempt '
'%d/%d.' % (snap_id, num_tries,
self.MAX_ATTEMPTS))
prev_rt = None
for rto in rt:
if (rto.status == 'succeeded'):
prev_rt = rto
break
sw = Sender(r, self.rep_ip, self.pubq, Queue(),
snap_name, self.meta_port,
self.data_port, r.meta_port,
self.uuid, snap_id, prev_rt)
else:
logger.error('unknown replica trail status: %s. '
'ignoring snap: %s' %
(rt[0].status, snap_id))
continue
self.senders[snap_id] = sw
sw.daemon = True
sw.start()
total_sleep = 0
except DatabaseError, e:
e_msg = ('Error getting the list of enabled replica '
'tasks. Moving on')
logger.error(e_msg)
logger.exception(e)
time.sleep(1)
total_sleep = total_sleep + 1
示例3: run
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import daemon [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
示例4: Sender
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import daemon [as 别名]
prev_rt = None
for rto in rt:
if (rto.status == 'succeeded'):
prev_rt = rto
break
sw = Sender(r, self.rep_ip, self.pubq, Queue(),
snap_name, self.meta_port,
self.data_port, r.meta_port,
self.uuid, snap_id, prev_rt)
else:
logger.error('unknown replica trail status: %s. '
'ignoring snap: %s' %
(rt[0].status, snap_id))
continue
self.senders[snap_id] = sw
sw.daemon = True
sw.start()
except DatabaseError, e:
e_msg = ('Error getting the list of enabled replica '
'tasks. Moving on. Exception: %s' % e.__str__())
logger.error(e_msg)
time.sleep(1)
total_sleep = total_sleep + 1
def main():
rs = ReplicaScheduler()
rs.start()
logger.debug('Started Replica Scheduler')
rs.join()
示例5: run
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import daemon [as 别名]
#.........这里部分代码省略.........
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
logger.debug(
"%s not found in senders. Previous "
"sender must have Aborted. Marking "
"it as failed" % prev_snap_id
)
msg = "Sender process Aborted. See logs for " "more information"
data = {
"status": "failed",
"end_ts": now.strftime(settings.SNAP_TS_FORMAT),
"error": msg,
"send_failed": now,
}
update_replica_status(rt[0].id, data, logger)
continue
elif rt[0].status == "failed":
snap_name = rt[0].snap_name
# if num_failed attempts > 10, disable the replica
num_tries = 0
for rto in rt:
if rto.status != "failed" or num_tries >= self.MAX_ATTEMPTS or rto.end_ts < r.ts:
break
num_tries = num_tries + 1
if num_tries >= self.MAX_ATTEMPTS:
logger.info(
"Maximum attempts(%d) reached "
"for snap: %s. Disabling the "
"replica." % (self.MAX_ATTEMPTS, snap_id)
)
disable_replica(r.id, logger)
continue
logger.info(
"previous backup failed for snap: "
"%s. Starting a new one. Attempt "
"%d/%d." % (snap_id, num_tries, self.MAX_ATTEMPTS)
)
prev_rt = None
for rto in rt:
if rto.status == "succeeded":
prev_rt = rto
break
sw = Sender(
r,
self.rep_ip,
self.pubq,
Queue(),
snap_name,
self.meta_port,
self.data_port,
r.meta_port,
self.uuid,
snap_id,
prev_rt,
)
else:
logger.error(
"unknown replica trail status: %s. " "ignoring snap: %s" % (rt[0].status, snap_id)
)
continue
self.senders[snap_id] = sw
sw.daemon = True
sw.start()
total_sleep = 0
except DatabaseError, e:
e_msg = "Error getting the list of enabled replica " "tasks. Moving on"
logger.error(e_msg)
logger.exception(e)
time.sleep(1)
total_sleep = total_sleep + 1