當前位置: 首頁>>代碼示例>>Python>>正文


Python Receiver.transition方法代碼示例

本文整理匯總了Python中receiver.Receiver.transition方法的典型用法代碼示例。如果您正苦於以下問題:Python Receiver.transition方法的具體用法?Python Receiver.transition怎麽用?Python Receiver.transition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在receiver.Receiver的用法示例。


在下文中一共展示了Receiver.transition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: emulate

# 需要導入模塊: from receiver import Receiver [as 別名]
# 或者: from receiver.Receiver import transition [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


注:本文中的receiver.Receiver.transition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。