Author bkabrda
Recipients bkabrda
Date 2014-07-01.10:01:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1404208895.06.0.521807683184.issue21895@psf.upfronthosting.co.za>
In-reply-to
Content
Reproducer attached. To describe the problem in words, one needs to do this to reproduce this issue:
- Create a signal handler and register it using signal.signal to SIGCHLD.
- Create a thread that invokes a subprocess, e.g. "sleep 1" and then continues to do something for time period longer than the subprocess is running.
- Run this thread from main thread and call signal.pause() in the main thread.
- The pause() call is never interrupted and the signal handler is never run.

This happens because:
- Python adds signal_handler as a handler to the specified signal and stores the passed Python function in structure Handlers.
- When signal.pause() is run, the main thread releases the GIL, so that other threads can run.
- The non-main thread gets to lease and actually invokes the subprocess and then continues to do something.
- When subprocess finishes, it sends the signal *to the thread that invoked it* (assuming this thread is still running). This means that the signal.pause() call is not interrupted and main thread continues to sleep.
- The non-main thread adds handler call to the list of pending calls using Py_AddPendingCall.
- Pending calls are checked in Py_MakePendingCalls, which is called in every iteration of the bytecode evaluation loop in PyEval_EvalFrameEx.
- The problem is that since pause() isn't un-paused and hangs forever, the evaluation loop never gets to another iteration, hence can't do any pending call.

This happens on all Python versions I've tried, using pthread threading.
I think this could *possibly* be solved by issuing a pthread_kill from the non-main thread to the main thread to wake it up, but I'm not sure what all the implications of such a change would be.
History
Date User Action Args
2014-07-01 10:01:35bkabrdasetrecipients: + bkabrda
2014-07-01 10:01:35bkabrdasetmessageid: <1404208895.06.0.521807683184.issue21895@psf.upfronthosting.co.za>
2014-07-01 10:01:34bkabrdalinkissue21895 messages
2014-07-01 10:01:34bkabrdacreate