1 Feb 04:59
how to ensure writes to stdout via stdio.StandardIO are completed before we shutdown the reactor?
Benjamin Rutt <rutt.4 <at> osu.edu>
2012-02-01 03:59:30 GMT
2012-02-01 03:59:30 GMT
Hi twisted community,
What’s the best way to ensure writes to stdout via stdio.StandardIO
are completed before we shutdown the reactor? The use case is to
emit an error message before we shutdown the reactor and stop our
program. Dummy code snippet:
--------------------------------------------
#!/usr/bin/python
from twisted.internet import reactor, stdio
from twisted.protocols.basic import LineReceiver
class StdinInteractor(LineReceiver):
delimiter = '\n'
def go():
stdio_proto = StdinInteractor()
stdio.StandardIO(stdio_proto)
stdio_proto.transport.write('did we get this message?\n')
if 0:
reactor.stop()
else:
reactor.callLater(1.0, reactor.stop)
reactor.callWhenRunning(go)
reactor.run()
--------------------------------------------
If I change ‘if 0’ to ‘if 1’, I don’t get the message on stdout. The
(Continue reading)
RSS Feed