STINNER Victor <victor.stin...@haypocalc.com> added the comment:

> 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?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8407>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to