<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 19, 2011, at 4:43 AM, Phil Mayers wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On 04/18/2011 11:36 AM, Ivan wrote:<br><blockquote type="cite">Thanks, but how to kill workers by timeout in this example ?<br></blockquote><br>You can't kill threads reliably in python AIUI.<br></div></blockquote><div><br></div><div>You can't kill threads in _any_ language reliably. &nbsp;There are certain special cases where you can <i>sort of</i>&nbsp;make it work in some specific C programs, but for more information read this explanation of why it's not possible to implement a generally correct 'stop this thread' API, see here: &lt;<a href="http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html">http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html</a>&gt;.</div><br><blockquote type="cite"><div>If you want to reliably kill a task, spawn a process.<br></div></blockquote><div><br></div><div>Yes, that's how you do it.</div><br><blockquote type="cite"><div>Alternatively you might see if you can break the task up into small <br>pieces of work, and schedule it in the mainloop using something like <br>task.cooperator.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>If the task is doing something CPU intensive, a subprocess will let you take advantage of multiple cores as well, though. &nbsp;If the task is small and cheap though, and just needs to be performed periodically cooperator lets you avoid the overhead of <i>both</i>&nbsp;processes and threads.</div><div><br></div><div>-g</div><div><br></div></body></html>