本文整理汇总了Python中sender.Sender.join方法的典型用法代码示例。如果您正苦于以下问题:Python Sender.join方法的具体用法?Python Sender.join怎么用?Python Sender.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sender.Sender
的用法示例。
在下文中一共展示了Sender.join方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emulate
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import join [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)