Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation between threads and signals unclear #58661

Closed
smarnach mannequin opened this issue Mar 30, 2012 · 7 comments
Closed

Relation between threads and signals unclear #58661

smarnach mannequin opened this issue Mar 30, 2012 · 7 comments
Labels
docs Documentation in the Doc dir

Comments

@smarnach
Copy link
Mannequin

smarnach mannequin commented Mar 30, 2012

BPO 14456
Nosy @pitrou, @vstinner, @smarnach

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 = None
closed_at = <Date 2012-03-31.19:15:45.741>
created_at = <Date 2012-03-30.23:12:58.024>
labels = ['docs']
title = 'Relation between threads and signals unclear'
updated_at = <Date 2016-04-11.02:47:20.948>
user = 'https://github.com/smarnach'

bugs.python.org fields:

activity = <Date 2016-04-11.02:47:20.948>
actor = 'python-dev'
assignee = 'docs@python'
closed = True
closed_date = <Date 2012-03-31.19:15:45.741>
closer = 'pitrou'
components = ['Documentation']
creation = <Date 2012-03-30.23:12:58.024>
creator = 'smarnach'
dependencies = []
files = []
hgrepos = []
issue_num = 14456
keywords = []
message_count = 7.0
messages = ['157156', '157158', '157160', '157222', '157223', '157238', '263160']
nosy_count = 6.0
nosy_names = ['pitrou', 'vstinner', 'neologix', 'docs@python', 'python-dev', 'smarnach']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue14456'
versions = ['Python 3.3']

@smarnach
Copy link
Mannequin Author

smarnach mannequin commented Mar 30, 2012

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.

@smarnach smarnach mannequin assigned docspython Mar 30, 2012
@smarnach smarnach mannequin added the docs Documentation in the Doc dir label Mar 30, 2012
@smarnach
Copy link
Mannequin Author

smarnach mannequin commented Mar 30, 2012

For reference: the functions 'pthread_kill()' etc. were intrduced in bpo-8407.

@vstinner
Copy link
Member

vstinner commented Mar 30, 2012

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.

@python-dev
Copy link
Mannequin

python-dev mannequin commented 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
Copy link
Member

pitrou commented Mar 31, 2012

Should be fixed now.

@pitrou pitrou closed this as completed Mar 31, 2012
@smarnach
Copy link
Mannequin Author

smarnach mannequin commented Mar 31, 2012

Thanks, Antoine! It's perfectly clear now, and the newly introduces headlines are a definite improvement.

@python-dev
Copy link
Mannequin

python-dev mannequin commented 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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

2 participants