读书人

twisted-简略启动

发布时间: 2012-10-27 10:42:26 作者: rapoo

twisted-简单启动

from twisted.internet import reactorimport timedef printTime():    print "current time is",time.strftime("%H:%M:%S")    def stopReactor():    print "stopping reactor"    reactor.stop()reactor.callLater(1,printTime)reactor.callLater(2,printTime)reactor.callLater(3,printTime)reactor.callLater(4,printTime)reactor.callLater(5,stopReactor)print "Running the reactor...."reactor.run()print "Reacotr stopped."

?

?

?reactor.callLater函数的第一个参数是要等待的秒,第二个参数是要调用的函数,后面还可以跟着参数,就是调用函数的参数

>>>
Running the reactor....
current time is 21:04:09
current time is 21:04:10
current time is 21:04:11
current time is 21:04:12
stopping reactor
Reacotr stopped.
>>>

读书人网 >编程

热点推荐