<div dir="ltr"><div dir="ltr">Hello list,</div><div dir="ltr"><br></div><div>I need to implement a graceful shutdown procedure for a twistd application.</div><div>The application is made up of two services: an internet.TCPClient and an internet.TCPServer.</div>
<div>They're glued together with a MultiService instance, which is in turn set to have 'application' as parent.</div><div>The server and the client work together, making a proxy (SMTP server and AMQP client).</div>
<div><br></div><div>My goal is the following:</div><div>- intercept a SIGTERM signal</div><div>- '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</div>
<div>- wait until current requests are satisfied (I keep a dictionary of current pending messages)</div><div>- shut the whole thing down</div><div><br></div><div>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).</div>
<div><br></div><div>Thank you very much for your help!</div><div><br></div><div>Fabio</div>
</div>