[Python-Dev] Signals+Threads (PyGTK waking up 10x/sec).

Gustavo Carneiro gjcarneiro at gmail.com
Sat Dec 8 19:20:15 CET 2007

On 08/12/2007, Guido van Rossum <guido at python.org> wrote:
> On Dec 8, 2007 9:20 AM, Guido van Rossum <guido at python.org> wrote:
> > The
> > handler must be written in C in order to avoid the race condition
> > referred to by Glyph (signals arriving after the signal check in the
> > VM main loop but before the select()/poll() system call is entered
> > will not be noticed until the select()/poll() call completes).
> Sorry, I misattributed this; Gustavo Carneiro pointed this out earlier
> in this thread.
> BTW, in the referenced post (also by Gustavo), I found this:
> """
> According to [1], all python needs to do to avoid this problem is
> block all signals in all but the main thread; then we can guarantee
> signal handlers are always called from the main thread, and pygtk
> doesn't need a timeout.
> [1] https://bugzilla.redhat.com/bugzilla/process_bug.cgi#c3
> """
> Unfortunately I can't read [1] without having registered, so I can
> only guess what it says.

I can't read [1] either because the URL is not correct.  Sorry :P

But I know that Python already ensures that
> signals are only delivered to the main thread.

Are you sure?  In python code I see pthread_sigmask being checked for in
configure.in, but I can't find it being used anywhere (unless I'm grepping
for the wrong thing).

What you probably meant to say was "python ensures that signals are only
processed from the main thread".

Except when python uses "GNU PTH threads"; there I do see signals being
delivered to the main thread.  But GNU pth are not real kernel threads,

What am I missing?

I think Python could make sure (via pthread_sigmask) that signals are
blocked for all non-main threads created by Python.  Unfortunately it cannot
do the same for threads not created by Python.  I know at least one case
where threads are created behing Python's back: the GnomeVFS library.

Best regards,

Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20071208/f512ac6c/attachment.htm 

More information about the Python-Dev mailing list