当前位置: 首页>>代码示例>>Python>>正文


Python Sender.consume_acks方法代码示例

本文整理汇总了Python中sender.Sender.consume_acks方法的典型用法代码示例。如果您正苦于以下问题:Python Sender.consume_acks方法的具体用法?Python Sender.consume_acks怎么用?Python Sender.consume_acks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sender.Sender的用法示例。


在下文中一共展示了Sender.consume_acks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: emulate

# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import consume_acks [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)
开发者ID:ModelInference,项目名称:synoptic,代码行数:61,代码来源:abp.py


注:本文中的sender.Sender.consume_acks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。