Almost a year ago I've created an issue in Python's bugtracker but the issue seems to be stuck since then so I'm sending the patch here in hope it could be included in ports collection.
In short there is a problem in the Python that can be seen under FreeBSD and Sun Solaris but not under MacOSX or Linux. The problem is that when a Python program started a thread in a background, then it can be impossible to interrupt the program with Ctrl-C.
The reason why this problem is FreeBSD specific is that the FreeBSD has different order of processing of signals. The signal handler under FreeBSD fires up in the context of the last started thread, while under Linux signals are processed in the main thread. It should be noted that both behaviors are standards conformant.
This bug at Python bugtracker: http://bugs.python.org/issue1975
Fix: To ensure that signal handler runs in the correct thread context the developer should use pthread_sigmask(). Initially the Python contained this code but starting from Python 2.4 it was thrown away.
The attached patch restores the code that ensures correct execution context of the signal handler code.
Patch attached with submission follows:
How-To-Repeat: Here is an example script. Start it and try to interrupt by hitting ^C.
from threading import Thread
some_time = 6000000 # seconds
t = MyThread()
select.select(, , , some_time)
Over to maintainer (via the GNATS Auto Assign Tool)
sobomax 2009-02-27 01:25:32 UTC
FreeBSD ports repository
Make sure the singal is delivered to the main thread, where python
runs its signal handlers, not to a random thread that happens to be
executing at the time when signal arrives. This functionality has been
lost since Python 2.3, possible cause is that the linux implementation
of POSIX threads always delivered signal to the main thread. This
bug results in rather annoying inability to terminate threading script
with ^C for example and there could be other issues as well.
Submitted by: Andriy Pylypenko <firstname.lastname@example.org>
Approved by: MAINTAINER's timeout
Revision Changes Path
1.166 +1 -1 ports/lang/python24/Makefile
1.1 +30 -0 ports/lang/python24/files/patch-Python_thread__pthread.h (new)
1.154 +1 -0 ports/lang/python25/Makefile
1.1 +30 -0 ports/lang/python25/files/patch-Python_thread__pthread.h (new)
1.156 +1 -1 ports/lang/python26/Makefile
1.1 +30 -0 ports/lang/python26/files/patch-Python_thread__pthread.h (new)
email@example.com mailing list
To unsubscribe, send any mail to "firstname.lastname@example.org"
Committed by sobomax 2009-02-27.