Message138042
> I just noticed something "funny": signal_sigwait doesn't release
> the GIL, which means that it's pretty much useless :-)
sigwait() is not useless: the signal is not necessary send by another thread. The signal can be send by alarm(), from a child process, by an user, by the kernel.
Releasing the GIL is a new feature. Because it is cheap and pause() does also release the GIL, I commited your patch.
> Also, test_sigwait doesn't block the signal before calling sigwait:
> it happens to work because there's only one thread, but it's
> undefined behaviour.
test_sigwait() test pass on all 3.x buildbots (some don't have sigwait(), the test is skipped). Sometimes, test_sigwait() is executed with 2 threads, the main thread and Tkinter event loop thread, and the signal is not blocked in any thread.
On Linux, it works well with more than one thread. I added a test using a thread, we will see if it works on buildbots. The signal is raised by a thread (whereas the signal is not blocked in any thread).
I wrote a can_test_blocked_signals() function in test_signal which has hardcoded tests to check for some known C threads: the faulthandler timeout thread and for the Tkinter event loop thread. can_test_blocked_signals() returns True if pthread_kill() is available.
I don't know how it works if a thread uses pthread_kill() to raise a signal into the main thread (waiting in sigwait()), whereas the signal is not blocked in any thread.
If it is not possible to get the list of all C/Python threads and/or block a signal in all threads, we can use a subprocess without threads (with only the main thread).
Would you like to work on a patch to avoid the undefined behaviour? |
|
Date |
User |
Action |
Args |
2011-06-09 23:54:23 | vstinner | set | recipients:
+ vstinner, loewis, gregory.p.smith, jcea, spiv, exarkun, tseaver, pitrou, giampaolo.rodola, benjamin.peterson, marcin.bachry, schmichael, skrah, neologix, python-dev |
2011-06-09 23:54:23 | vstinner | set | messageid: <1307663663.89.0.41178639954.issue8407@psf.upfronthosting.co.za> |
2011-06-09 23:54:23 | vstinner | link | issue8407 messages |
2011-06-09 23:54:23 | vstinner | create | |
|