Hi,
I'm a new user of both twisted and thrift, and I need for my project to be able
to call multiple times reactor.run (essentially for running unit tests).
I know this post is more about twisted, but this is probably the first of many
posts related to thrift+twisted, which is more my focus :)
I've searched everywhere on how to do that, but not to prevail. See below the
example program.
The symptom is that the second reactor.stop never succeeds, and "Success" is
never printed.
(notice I tried with and without 'reactor_clean_up'which is a code I found in
twisted unit test, which seemed to allow for that)
This is using latest twisted, both on Ubuntu Lucid + 10.0.1 (PPA), and Windows.
Sorry if I'm asking at the wrong location, and don't know yet what is the
process to ask those kind of questions.
Many thanks in advance!
Alex
>>>>>>>> CUT >>>>>>>>>>>>
from twisted.internet import reactor
def reactor_clean_up():
reactor._uninstallHandler()
if getattr(reactor, '_internalReaders', None) is not None:
for reader in reactor._internalReaders:
reactor.removeReader(reader)
reader.connectionLost(None)
reactor._internalReaders.clear()
# Here's an extra thing unrelated to wakers but necessary for
# cleaning up after the reactors we make. -exarkun
reactor.disconnectAll()
# It would also be bad if any timed calls left over were allowed to
# run.
calls = reactor.getDelayedCalls()
for c in calls:
c.cancel()
print "1st call to reactor"
reactor.callLater(2, reactor.stop)
reactor.run(installSignalHandlers=False)
reactor_clean_up()
print "2nd call to reactor"
reactor.callLater(2, reactor.stop)
reactor.run(installSignalHandlers=False)
print "Success"
>>>>>>>> CUT >>>>>>>>>>>>