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.
>>>