<br><br><div class="gmail_quote">On Tue, Jul 24, 2012 at 11:18 PM, Tom Sheffler <span dir="ltr">&lt;<a href="mailto:tom.sheffler@gmail.com" target="_blank">tom.sheffler@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Hi Twisted Folks,</div><div><br></div><div>We use monit to start and stop our twistd daemons.  I have set up monit to restart some of the daemons when they grow too large.  I use the following command:</div><div><br>
</div>
<div>    /bin/bash -c &#39;kill -s SIGTERM `cat /var/run/sensrtunw/sensrtunw.pid`&#39;</div><div><br></div><div>Occasionally, this is unsuccessful in killing the twistd process, and I need to use a SIGKILL manually as a last resort.</div>

<div><br></div><div>Any ideas why?</div><br></blockquote><div>What do the logs say? You should get a log message saying something like &quot;Received SIGTERM&quot;, anything in the logs after that which indicates what code is continuing to run?<br>
<br>Threads might be an issue, but not necessarily as a race condition. Do you see a message about the reactor shutting down (&quot;Main loop terminated&quot;), but the process is still running? Python processes won&#39;t exit if there are still threads running. So if you have a thread that&#39;s doing a long running database query, the reactor may have stopped, and the thread pool may have been told to shutdown, but that thread will still be running waiting for a reply from the database. In this case, unless the database connection is wedged, simply waiting long enough will let the process exit.<br>
<br>Another thing which might prevent shutdown is having a Service with a stopService that returns a Deferred; until that Deferred fires the reactor won&#39;t stop. Again, looking at logs should be helpful, since you won&#39;t actually see the final reactor shutdown message (&quot;Main loop terminated.&quot;).<br>
</div></div><br>-- <br>Itamar Turner-Trauring, Future Foundries LLC<br><a href="http://futurefoundries.com/" target="_blank">http://futurefoundries.com/</a> — Twisted consulting, training and support.<br><br>