Antoine Pitrou added the comment:

Ok, I think I've managed to dig to the core issue.  It is actually the same 
issue as https://bugs.python.org/issue11768 (which was wrongly closed as fixed, 
apparently :-)).

Py_AddPendingCall() calls PyThread_acquire_lock() to try and take the pending 
calls lock.  Unfortunately, PyThread_acquire_lock() is not reentrant in the 
case where semaphores are not used (e.g. on OS X).  We can probably fix that 
first issue by calling pthread_mutex_trylock() instead of pthread_mutex_lock().

There is a second more fundamental issue, though, which is that 
PyThread_acquire_lock() calls into functions that are not async-signal-safe 
(see http://man7.org/linux/man-pages/man7/signal-safety.7.html for a list).  
So, depending on the particular OS and libc implementation, 
PyThread_acquire_lock() can fail in mysterious ways (including hang the 
process) when called from a signal handler.

So perhaps the ultimate fix would be to remove the OS-based locking in 
Py_AddPendingCall and use a busy spinwait...  The performance implications may 
be bad, though.

----------
nosy: +neologix, njs
versions: +Python 2.7, Python 3.5, Python 3.6

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

Reply via email to