[Twisted-Python] Calling reactor.run() / reactor.stop() twice

John Dawson jdawson at io.com
Tue Nov 13 16:43:23 EST 2007


Hi,

The following Twisted code hangs, since the second call to
reactor.stop() doesn't seem to really stop the reactor.  Is this a bug
in Twisted, or is it impermissible to run/stop a reactor more than
once?

#!/opt/local/bin/python2.5

from twisted.internet import reactor

def ping():
    def stop_reactor():
        print "stopping reactor"
        reactor.stop()
    print "Ping: ENTER"
    print "Setting up timer for callback"
    reactor.callLater(0.25, stop_reactor)
    print "Running reactor"
    reactor.run()
    print "Reactor stopped"
    print "Ping: EXIT"

print "ping1"
ping()
print
print "ping2"
ping()


It prints:

$ ./reactor1.py
ping1
Ping: ENTER
Setting up timer for callback
Running reactor
stopping reactor
Reactor stopped
Ping: EXIT

ping2
Ping: ENTER
Setting up timer for callback
Running reactor
stopping reactor

And then hangs.

Any help/advice appreciated.

John

-- 
John Dawson <jdawson at io.com>




More information about the Twisted-Python mailing list