本文整理匯總了Python中twisted.internet.defer.DeferredSemaphore.ctr方法的典型用法代碼示例。如果您正苦於以下問題:Python DeferredSemaphore.ctr方法的具體用法?Python DeferredSemaphore.ctr怎麽用?Python DeferredSemaphore.ctr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.defer.DeferredSemaphore
的用法示例。
在下文中一共展示了DeferredSemaphore.ctr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_message
# 需要導入模塊: from twisted.internet.defer import DeferredSemaphore [as 別名]
# 或者: from twisted.internet.defer.DeferredSemaphore import ctr [as 別名]
from config import MAX_CONNECT
def send_message(endpoint, dispatcher):
outgoing_message = VOEventMessage(LOCAL_IVO)
if dispatcher.ctr == N_OF_EVENTS:
dispatcher.loop.stop()
else:
dispatcher.ctr += 1
def do_send():
# Set up a factory connected to the relevant endpoint
d = endpoint.connect(VOEventSenderFactory())
# And when the connection is ready, use it to send a message
d.addCallback(lambda p: p.sendString(outgoing_message.to_string()))
# The semaphore releases when the returned Deferred fires
return d
dispatcher.run(do_send)
if __name__ == "__main__":
log.startLogging(sys.stdout)
endpoint = clientFromString(reactor, CONNECT_TO)
dispatcher = DeferredSemaphore(MAX_CONNECT)
dispatcher.loop = task.LoopingCall(send_message, endpoint, dispatcher)
dispatcher.ctr = 1
dispatcher.loop.start(float(PERIOD)/N_OF_EVENTS)
reactor.run()