[Python-Dev] Signals, threads, blocking C functions
Chris McDonough
chrism at plope.com
Mon Sep 4 04:36:23 CEST 2006
Would adding an API for sigprocmask help here?
(Although it has been tried before -- http://mail.python.org/
pipermail/python-dev/2003-February/033016.html and died in the womb
due to threading-related issues -- http://mail.mems-exchange.org/
durusmail/quixote-users/1248/)
- C
On Sep 2, 2006, at 8:10 AM, Gustavo Carneiro wrote:
> We have to resort to timeouts in pygtk in order to catch unix signals
> in threaded mode.
> The reason is this. We call gtk_main() (mainloop function) which
> blocks forever. Suppose there are threads in the program; then any
> thread can receive a signal (e.g. SIGINT). Python catches the signal,
> but doesn't do anything; it simply sets a flag in a global structure
> and calls Py_AddPendingCall(), and I guess it expects someone to call
> Py_MakePendingCalls(). However, the main thread is blocked calling a
> C function and has no way of being notified it needs to give control
> back to python to handle the signal. Hence, we use a 100ms timeout
> for polling. Unfortunately, timeouts needlessly consume CPU time and
> drain laptop batteries.
>
> 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.
>
> Another alternative would be to add a new API like
> Py_AddPendingCallNotification, which would let python notify
> extensions that new pending calls exist and need to be processed.
>
> But I would really prefer the first alternative, as it could be
> fixed within python 2.5; no need to wait for 2.6.
>
> Please, let's make Python ready for the enterprise! [2]
>
> [1] https://bugzilla.redhat.com/bugzilla/process_bug.cgi#c3
> [2] http://perkypants.org/blog/2006/09/02/rfte-python/
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/lists
> %40plope.com
>
More information about the Python-Dev
mailing list