- 论坛徽章:
- 0
|
- from twisted.internet.threads import deferToThread
- deferred = deferToThread.__get__
- ## example code
- def print_(result):
- print result
-
- def running():
- "Prints a few dots on stdout while the reactor is running."
- sys.stdout.write("."); sys.stdout.flush()
- reactor.callLater(.1, running)
- @deferred
- def sleep(sec):
- "A blocking function magically converted in a non-blocking one."
- print 'start sleep %s' % sec
- time.sleep(sec)
- print '\nend sleep %s' % sec
- return "ok"
-
- if __name__ == "__main__":
- sleep(2).addBoth(print_)
- reactor.callLater(.1, running)
- reactor.callLater(3, reactor.stop)
- reactor.run()
复制代码
就是这句话 @deferred
其中的 @ 是什么用法,那里有讲的? |
|