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