Signals, threads, blocking C functions
From: | "Gustavo Carneiro" <gjcarneiro-AT-gmail.com> | |
To: | python-dev-AT-python.org | |
Subject: | Signals, threads, blocking C functions | |
Date: | Sat, 2 Sep 2006 13:10:04 +0100 |
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@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-...
Posted Sep 7, 2006 18:45 UTC (Thu)
by oak (guest, #2786)
[Link] (1 responses)
Posted Sep 7, 2006 19:22 UTC (Thu)
by zlynx (guest, #2285)
[Link]
Looks like gnome-vfs uses g_thread from glib instead of pthreads. Although, it seems pthreads are used by glib, so...
Don't threads usually invoke each other with pipes (e.g. in Gnome-VFS)? Signals, threads, blocking C functions
Usually I see pthread_cond_signal and pthread_cond_wait used. These are implemented with futexes in NPTL. It could have been pipes in LinuxThreads.Signals, threads, blocking C functions