Hi all,<br> 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.
<br><br> 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? <br><br> Thank you in advance.
<br><br> The session is listed here:<br><br>>>> from twisted.internet import reactor<br>>>> import time<br>>>> def printTime():<br> print "Current time is ", time.strftime("%H:%M:%S")
<br><br> <br>>>> def stopReactor():<br> printTime()<br> print "Stopping reactor"<br> reactor.stop()<br><br> <br>>>> reactor.callLater(1, printTime)<br><twisted.internet.base.DelayedCall
instance at 0x00D9E288><br>>>> reactor.callLater(2, printTime)<br><twisted.internet.base.DelayedCall instance at 0x00E42210><br>>>> reactor.callLater(3, printTime)<br><twisted.internet.base.DelayedCall
instance at 0x00DF8BC0><br>>>> reactor.callLater(4, printTime)<br><twisted.internet.base.DelayedCall instance at 0x00C74760><br>>>> reactor.callLater(5, stopReactor)<br><twisted.internet.base.DelayedCall
instance at 0x0132E738><br>>>> reactor.run()<br>Current time is 09:06:52<br>Current time is 09:06:52<br>Current time is 09:06:52<br>Current time is 09:06:52<br>Current time is 09:06:52<br>Stopping reactor
<br><br><br>