On 08/12/2007, <b class="gmail_sendername">Guido van Rossum</b> &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Dec 8, 2007 9:20 AM, Guido van Rossum &lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt; wrote:<br>&gt; The<br>&gt; handler must be written in C in order to avoid the race condition<br>&gt; referred to by Glyph (signals arriving after the signal check in the
<br>&gt; VM main loop but before the select()/poll() system call is entered<br>&gt; will not be noticed until the select()/poll() call completes).<br><br>Sorry, I misattributed this; Gustavo Carneiro pointed this out earlier
<br>in this thread.<br><br>BTW, in the referenced post (also by Gustavo), I found this:<br><br>&quot;&quot;&quot;<br>According to [1], all python needs to do to avoid this problem is<br>block all signals in all but the main thread; then we can guarantee
<br>signal handlers are always called from the main thread, and pygtk<br>doesn&#39;t need a timeout.<br><br>[1] <a href="https://bugzilla.redhat.com/bugzilla/process_bug.cgi#c3">https://bugzilla.redhat.com/bugzilla/process_bug.cgi#c3
</a><br>&quot;&quot;&quot;<br><br>Unfortunately I can&#39;t read [1] without having registered, so I can<br>only guess what it says.</blockquote><div><br>I can&#39;t read [1] either because the URL is not correct.&nbsp; Sorry :P 
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> But I know that Python already ensures that<br>signals are only delivered to the main thread.
</blockquote><div><br>Are you sure?&nbsp; In python code I see pthread_sigmask being checked for in <a href="http://configure.in">configure.in</a>, but I can&#39;t find it being used anywhere (unless I&#39;m grepping for the wrong thing).
<br><br>What you probably meant to say was &quot;python ensures that signals are only processed from the main thread&quot;. <br><br>Except when python uses &quot;GNU PTH threads&quot;; there I do see signals being delivered to the main thread.&nbsp; But GNU pth are not real kernel threads, anyway.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> What am I missing?</blockquote><div><br>I think Python could make sure (via pthread_sigmask) that signals are blocked for all non-main threads created by Python.&nbsp; Unfortunately it cannot do the same for threads not created by Python.&nbsp; I know at least one case where threads are created behing Python&#39;s back: the GnomeVFS library.
<br><br>Best regards,<br><br></div></div>-- <br>Gustavo J. A. M. Carneiro<br>INESC Porto, Telecommunications and Multimedia Unit<br>&quot;The universe is always one step beyond logic.&quot; -- Frank Herbert