[Twisted-Python] Graceful shutdown of twistd application
Fabio Sangiovanni
sangiovanni at nweb.it
Thu Sep 4 04:52:07 MDT 2014
Hello list,
I need to implement a graceful shutdown procedure for a twistd application.
The application is made up of two services: an internet.TCPClient and
an internet.TCPServer.
They're glued together with a MultiService instance, which is in turn set
to have 'application' as parent.
The server and the client work together, making a proxy (SMTP server and
AMQP client).
My goal is the following:
- intercept a SIGTERM signal
- 'block' on the server side: since it's SMTP I get this by setting a
variable that makes the server return tempfails (4xx) for new messages,
while keeping current sessions active
- wait until current requests are satisfied (I keep a dictionary of current
pending messages)
- shut the whole thing down
What is the best solution for this use case? It's not really clear to me
how to catch SIGTERM and handle pending requests *before* the underlying
services start to shutdown (i.e. even addSystemEventTrigger('before',
'shutdown', callable) is called too late for my needs).
Thank you very much for your help!
Fabio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140904/28f249a8/attachment.html>
More information about the Twisted-Python
mailing list