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

2016-07-29 Thread steven meier
hi, i ran into this issue, i can run the code on its own "python working_code.py", but i cant import it...how do you fit the reactor in this scenario? python main_code.py Unhandled error in Deferred: Traceback (most recent call last): File "/home/julius/.local/lib

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

2016-07-29 Thread Daniel Sank
Looks like the problem is that the twisted.internet.reactor is imported inside a block guarded by if __name__ == '__main__' When you import working_code that block doesn't run, because of the guard, so terrific_method tries to access "reactor" which doesn't exist. I guess your question is really

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

2016-07-29 Thread meejah
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 me

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

2016-07-29 Thread steven meier
On Fri, 2016-07-29 at 23:11 +0400, meejah wrote: > 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

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

2016-07-29 Thread meejah
steven meier writes: > if __name__ == '__main__': > import qt5reactor > qt5reactor.install() > from twisted.internet import reactor > reactor.callWhenRunning(print_it, reactor) > reactor.run() For "client-style" things (I guess I just mean "something that exits"), there's eve