Skip to content

forkserver throws a TypeError if default SIGINT handler is not used #159418

Open

Description

@itrowbri

Bug report

If a profiler or other program sets a SIGINT signal handler, forkserver eventually throws a TypeError. forkserver became the default start method in 3.14, causing code that was previously fine to fail.

Reproducer

Small setup to reproduce the bug below. Call the first program below foreign_sigint.c

  #define _GNU_SOURCE
  #include <signal.h>
  static void myhandler(int sig) { (void) sig; }
  __attribute__((constructor))
  static void install_handler(void)
  {
      struct sigaction sa;
      sigemptyset(&sa.sa_mask);
      sa.sa_flags   = 0;
      sa.sa_handler = myhandler;
      sigaction(SIGINT, &sa, NULL);
  }

Then call the python script below repro.py:

import multiprocessing, signal, sys

def work(x):
    return abs(x)

if __name__ == "__main__":
    print("python:", sys.version.split()[0])
    print("default start method:", multiprocessing.get_start_method())
    print("getsignal(SIGINT) ->", signal.getsignal(signal.SIGINT))
    p = multiprocessing.Process(target=work, args=(-1,))
    p.start()
    p.join()
    print("worker exitcode:", p.exitcode)

Then we can reproduce the bug with the following compilation/execution below.

$ gcc -shared -fPIC -o foreign_sigint.so foreign_sigint.c
$ python3 repro.py
python: 3.14.8
default start method: forkserver
getsignal(SIGINT) -> <built-in function default_int_handler>
worker exitcode: 0

$ LD_PRELOAD=./foreign_sigint.so python3 repro.py
python: 3.14.8
default start method: forkserver
getsignal(SIGINT) -> None
Traceback (most recent call last):
  File ".../multiprocessing/forkserver.py", line 353, in main
    code = _serve_one(child_r, fds,
                      unused_fds,
                      old_handlers)
  File ".../multiprocessing/forkserver.py", line 383, in _serve_one
    signal.signal(sig, val)
    ~~~~~~~~~~~~~^^^^^^^^^^
  File ".../signal.py", line 58, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object
worker exitcode: 1

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Activity

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

    stdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions