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

Sam Roberts sroberts at uniserve.com
Tue Sep 25 15:11:47 MDT 2007


Thank you both for your prompt help.

On Tue, Sep 25, 2007 at 03:51:24PM -0400, Jean-Paul Calderone wrote:
> On Tue, 25 Sep 2007 12:45:07 -0700, Sam Roberts <sroberts at uniserve.com> 
> None of the reactors implemented in Twisted are restartable.  You can call
> each of start and stop at most once.

Ok. Sorry to gripe, but it would have saved me some time had this rather
significant and non-obvious limitation been mentioned in the docs.

> If you are writing unit tests which require the reactor to run, then you
> can either use trial and twisted.trial.unittest.TestCase or you can write

Can you point me to any examples of using trial? The api is fairly
opaque, I'm baffled as to where to start, though the description sounds
like it was built to help with this problem.

> tests which cover smaller units of functionality (and hence do not require
> the reactor to be running).  I'd suggest the latter as better general unit
> testing practice.

I have unittests for the low-level code.  The purpose of these unit
tests is explicitly to ensure my implementation of the IWriteDescriptor
interfaces correctly interworks with the reactor.

For example, implementors of the IWriteDescriptor interface are required
to implement logPrefix(). This is not documented, and I am happy to have
discovered it now in my unit tests, rather than during later system tests
with the entire application.

On Tue, Sep 25, 2007 at 03:52:35PM -0400, Benjamin Henry wrote:
> 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?

No, not necessary. I am manually chaining my tests together as you
suggest.

It works OK, but from unittest's perspective, I now have only one
testcase, with everything bundled into a single reactor.run(). There are
some nice things about having multiple tests inside a unittest.TestCase,
such as not having every test that uses the reactor coupled together,
but I can do without this niceties.

Cheers,
Sam





More information about the Twisted-Python mailing list