twisted-简单启动

from twisted.internet import reactor
print "Running the reactor..."
reactor.run()
print "Ractor stopped."

按ctrl+c结束,因为 

 

>>>
Running the reactor...
Ractor stopped.
>>>

 

 

from twisted.internet import reactor
import time
def 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.
>>>

你可能感兴趣的:(启动)