Skip to content

posixmodule uses PyOS_setsig to save & restore signal handlers #114727

Open

Description

@encukou

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

Activity

  1. added
    extension-modules
    on Jan 29, 2024
  2. added a commit that references this issue on Mar 19, 2024
  3. corona10 commented on Mar 19, 2024

    @corona10
    Member

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulestopic-free-threading

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions