Chinaunix
标题:
python 中的 @ 是什么意思???
[打印本页]
作者:
血饮狂刀
时间:
2005-10-27 17:11
标题:
python 中的 @ 是什么意思???
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
其中的 @ 是什么用法,那里有讲的?
作者:
sakulagi
时间:
2005-10-27 20:55
标题:
python 中的 @ 是什么意思???
deferred是twisted里边定义的一个decorator。decorator是Python 2.4里新引入的一个概念。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2