[Twisted-Python] running code on its own and importing, howto install a different reactor?
steven meier
commercials24 at yahoo.de
Fri Jul 29 12:13:16 MDT 2016
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/python2.7/site-packages/twisted/internet/defer.py", line 1274, in unwindGenerator
return _inlineCallbacks(None, gen, Deferred())
File
"/home/julius/.local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1128, in _inlineCallbacks
result = g.send(result)
File
"/home/julius/code/python/qt5-python2.x/example/working_code.py", line
7, in print_it
arg = yield terrific_method()
File
"/home/julius/.local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1274, in unwindGenerator
return _inlineCallbacks(None, gen, Deferred())
--- <exception caught here> ---
File
"/home/julius/.local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1128, in _inlineCallbacks
result = g.send(result)
File
"/home/julius/code/python/qt5-python2.x/example/working_code.py", line
14, in terrific_method
reactor.callLater(2, d.callback, 2)
exceptions.NameError: global name 'reactor' is not defined
cat main_code.py
import qt5reactor
qt5reactor.install()
from twisted.internet import reactor
from working_code import print_it
print_it()
cat working_code.py
from twisted.internet.defer import inlineCallbacks, Deferred,
returnValue
@inlineCallbacks
def print_it():
arg = yield terrific_method()
print arg
@inlineCallbacks
def terrific_method():
d = Deferred()
reactor.callLater(2, d.callback, 2)
result = yield d
returnValue(result)
if __name__ == '__main__':
import qt5reactor
qt5reactor.install()
from twisted.internet import reactor
reactor.callWhenRunning(print_it)
reactor.run()
More information about the Twisted-Python
mailing list