On Tue, 2009-12-08 at 13:50 +0100, Gabriel Rossetti wrote:
> I have to send a message just before my service quits, but sometimes the 
> reactor quits before the msg is sent.
> I was wondering if I should user reactor.callLater like so :
...
> (which I don't really like), or use reactor.callFromThread like so :
...

Neither of these will necessarily work. Instead, you want to use a
shutdown hook:

reactor.addSystemEventTrigger("before", "shutdown", f)

when you do reactor.stop(), f will be called... and shutdown will be
delayed until the Deferred f returns is triggered. In your case, send
message, tell connection to close, and then stop reactor. If you make
sure the Deferred from f only gets callback()ed when connectionLost is
called you'll get behavior you want.


_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to