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

Benjamin Henry bhenry at pacecocorp.com
Tue Sep 25 15:52:35 EDT 2007

This response won't be as elegant as some, but you can't start the
reactor twice in the same process.  You can stop the reactor when the
service is ended (client or server), but with twistd, it starts and
stops itself.  

So, is it necessary that you start and stop the reactor to run the tests
in your code?  Why not make each test a callback?

Ben Henry
-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com
[mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of Sam
Sent: Tuesday, September 25, 2007 12:45 PM
To: twisted
Subject: [Twisted-Python] reactor.stop() doesn't stop the select

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)
        print "stop died!"

print "reactor stopped"
# Unreachable, why?
print "reactor stopped"
print "reactor stopped"

Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list