[Twisted-Python] Newbie Q: The first example in Fettig's book confused me
Hi all, I'm a new Python programmer and just picked up Abe Fettig's "Twisted" book. I tried out the first example, which use reactor.run() to drive printTime and stopReactor callback functions to print time, and found some strange things. I wrote the code in a .py file and run it, it's fine. However, when I tried to write the code in interactive mode and run it from IDLE shell window, all the four printTime were called at once. Why? Thank you in advance. The session is listed here:
from twisted.internet import reactor import time def printTime(): print "Current time is ", time.strftime("%H:%M:%S")
def stopReactor(): printTime() 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) reactor.run() Current time is 09:06:52 Current time is 09:06:52 Current time is 09:06:52 Current time is 09:06:52 Current time is 09:06:52 Stopping reactor
participants (3)
-
David Pratt
-
glyph@divmod.com
-
Mike Meng