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

posixmodule uses PyOS_setsig to save & restore signal handlers #114727

Open
encukou opened this issue Jan 29, 2024 · 1 comment
Open

posixmodule uses PyOS_setsig to save & restore signal handlers #114727

encukou opened this issue Jan 29, 2024 · 1 comment
Labels
extension-modules C modules in the Modules dir topic-free-threading

Comments

@encukou
Copy link
Member

encukou commented Jan 29, 2024

posixmodule ignores signals in os_openpty_impl and os_grantpt_impl by wrapping them in two PyOS_setsig calls:

   sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL);
    ...
    PyOS_setsig(SIGCHLD, sig_saved);

This relies on the GIL being held, so it probably needs a dedicated lock in free-threading builds.

Linked PRs

@corona10
Copy link
Member

corona10 commented Mar 19, 2024

@colesbury @erlend-aasland
Hmm, Do we need something like per signal API lock for the interpreter-wide that acquires lock when we need to call PyOS_setsig at any moment?

For example, if any thread needs to call PyOS_setsig or PyOS_getsig, is it required to acquire the specific interpreter-wise lock?

Py_BEGIN_CRITICAL_SECTION(interp->signal);
PyOS_setsig
..

PyOS_getsig
...
Py_END_CRITCIAL_SECTION();

And then add assertion(_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED) inside of PyOS_setsig abnd PyOS_getsig

Or instead we can use lightweight locking API for the same purpose.

note: IIUC, PyOS_setsig is process-wide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir topic-free-threading
Projects
None yet
Development

No branches or pull requests

3 participants