[Twisted-Python] reactor.stop() doesn't stop the select reactor?

Sam Roberts sroberts at uniserve.com
Tue Sep 25 15:45:07 EDT 2007


I have unittests where each test:

  def test_this
     .. setup
     reactor.run() # ... when test is done reactor.stop() will be called

  def test_that
     .. same as above


does some setup, runs the reactor until test is complete, then stops the
reactor, asserting all went as intended.

However, second call to reactor.stop() doesn't stop the reactor. strace
shows reactor going back into select(), blocking forever, but killable
with sigquit.

Is this really intentional?

Example code and testrun follow.

~/w/engine % python t_reactor_stop.py
2.5.1 (r251:54863, May  2 2007, 16:27:44)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)]
[twisted, version 2.5.0]
<twisted.internet.selectreactor.SelectReactor object at 0x2b684344a310>
stopping reactor running? 1
reactor stopped
stopping reactor running? 1
zsh: quit (core dumped)  python t_reactor_stop.py



~/w/engine % cat t_reactor_stop.py
import sys

print sys.version

from twisted.internet import reactor

import twisted

print twisted._version.version
print reactor

def stop_reactor():
    print "stopping reactor running? " + repr(reactor.running)
    try:
        reactor.stop()
    except:
        print "stop died!"

reactor.callWhenRunning(stop_reactor)
reactor.run()
print "reactor stopped"
reactor.callWhenRunning(stop_reactor)
reactor.run()
# Unreachable, why?
print "reactor stopped"
reactor.callWhenRunning(stop_reactor)
reactor.run()
print "reactor stopped"






More information about the Twisted-Python mailing list