You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Relation between threads and signals unclear #58661
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-03-31.19:15:45.741>created_at=<Date2012-03-30.23:12:58.024>labels= ['docs']
title='Relation between threads and signals unclear'updated_at=<Date2016-04-11.02:47:20.948>user='https://github.com/smarnach'
The documentation of the 'signal' module states on the one hand
[T]he main thread will be the only one to receive signals (this is
enforced by the Python signal module, even if the underlying thread
implementation supports sending signals to individual threads).
On the other hand, it provides the function 'pthread_kill()':
Send the signal signum to the thread thread_id, another thread in
the same process as the caller. The signal is asynchronously
directed to thread.
These two passages are in contradiction to each other. The documentation also states that only the main thread can set signal handlers -- if this is true, it is utterly unclear how sending signals to other threads is useful.
Probably the documentation wasn't fully updated when the above function was introduced.
These two passages are in contradiction to each other.
By default, a thread signal can receive any signal and the signal handler implemented in C will be called in the context of the thread.
CPython ensures that a signal handler implemented in Python and installed by signal.signal() will be called in the main thread. It uses a signal handler implemented in C which only store the notification and will be the Python signal handler later (as early as possible).
pthread_sigmask() can be used to mask some signals (or all signals) on a specific thread.
Activity
smarnach commentedon Mar 30, 2012
The documentation of the 'signal' module states on the one hand
On the other hand, it provides the function 'pthread_kill()':
These two passages are in contradiction to each other. The documentation also states that only the main thread can set signal handlers -- if this is true, it is utterly unclear how sending signals to other threads is useful.
Probably the documentation wasn't fully updated when the above function was introduced.
smarnach commentedon Mar 30, 2012
For reference: the functions 'pthread_kill()' etc. were intrduced in bpo-8407.
vstinner commentedon Mar 30, 2012
By default, a thread signal can receive any signal and the signal handler implemented in C will be called in the context of the thread.
CPython ensures that a signal handler implemented in Python and installed by signal.signal() will be called in the main thread. It uses a signal handler implemented in C which only store the notification and will be the Python signal handler later (as early as possible).
pthread_sigmask() can be used to mask some signals (or all signals) on a specific thread.
python-dev commentedon Mar 31, 2012
New changeset 52e32f3b933d by Antoine Pitrou in branch '3.2':
Issue bpo-14456: improve documentation of the signal module w.r.t. threads.
http://hg.python.org/cpython/rev/52e32f3b933d
New changeset 44d13f371811 by Antoine Pitrou in branch 'default':
Issue bpo-14456: improve documentation of the signal module w.r.t. threads.
http://hg.python.org/cpython/rev/44d13f371811
pitrou commentedon Mar 31, 2012
Should be fixed now.
smarnach commentedon Mar 31, 2012
Thanks, Antoine! It's perfectly clear now, and the newly introduces headlines are a definite improvement.
python-dev commentedon Apr 11, 2016
New changeset 73050563053f by Martin Panter in branch '3.5':
Issue bpo-14456: Remove contradiction about blocking signals from bad merge
https://hg.python.org/cpython/rev/73050563053f
New changeset a8dbe6016a31 by Martin Panter in branch 'default':
Issue bpo-14456: Merge signal doc fix from 3.5
https://hg.python.org/cpython/rev/a8dbe6016a31