【发布时间】:2015-02-06 07:03:14
【问题描述】:
为什么这个python高速公路示例代码使用yield sleep(1)而不是简单的sleep(1)?
class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
@inlineCallbacks
def onJoin(self, details):
print("session attached")
counter = 0
while True:
print(".")
self.publish('com.myapp.topic1', counter)
counter += 1
yield sleep(1)
if __name__ == '__main__':
from autobahn.twisted.wamp import ApplicationRunner
runner = ApplicationRunner("ws://127.0.0.1:8080/ws", "realm1")
runner.run(Component)
【问题讨论】:
标签: python python-2.7 twisted autobahn