[Twisted-Python] running code on its own and importing, howto install a different reactor?

meejah meejah at meejah.ca
Fri Jul 29 13:11:56 MDT 2016


I think the "recommended" way to get access to a reactor instance is to
pass it in to methods that require it.

While this can sometimes seem tedious it a) helps testing (because now
you can easily pass a fake reactor object like Clock or a Mock instance)
and b) shows you (and your users) which methods are (or might-be) async.

So, try a signature like "def terrific_method(reactor):" instead. Now
when you're writing tests, you can do this:

    fake_reactor = Clock()
    d = terrific_method(fake_reactor)
    fake_reactor.advance(2)
    # etc.

-- 
meejah




More information about the Twisted-Python mailing list