[Twisted-Python] Global reactor unit tests in the Twisted test suite

Glyph glyph at twistedmatrix.com
Tue Nov 1 19:58:33 EDT 2011

On Nov 1, 2011, at 4:36 PM, Phil Mayers wrote:

> One example, we use a tiny script wrapping DeferredSemaphore and 
> t.p.utils.getProcessOutput to parallelise SSH scanning, because 
> ssh-keyscan is (ahem) poorly implemented.
> Maybe I knock up more of these short 20-liners than is common? And 
> typing "reactor, " a lot in them seems a bit, well... retrograde.

Hopefully you only need to pass it in at the top level to a few things, not everywhere to everything :).

For example, with something like twisted.web.client.Agent, you pass the reactor once and then you have an object you can call methods on, you don't need to keep repeating it.  If getProcessOutput were a method of a more helpful object, perhaps you'd be able to type 'reactor' a bit less.

Another possible eventual improvement here is that Twisted include a script-running tool which creates the reactor for you and passes it, either to a specified function or as a magic global in a script.  Then you should just pass 'reactor' to the top-level stuff in your script.  Sort of like 'twistd' but for one-off things where you don't want to go to the trouble to build a plugin or even a Service.

As a bonus, such a tool could call 'reactor.run()' for you automatically, eliminating some newbie confusion about when it's appropriate to do that.  (And ideally, 'reactor.stop' when some appropriate Deferred is fired, but that gets into more thinking than I want to do about this right now...)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20111101/043a6bde/attachment.htm 

More information about the Twisted-Python mailing list