Skip to content

Test suite hangs forever when run as a background job (SIGINT ignored) #154167

Description

@serhiy-storchaka

Bug report

When the test suite is started as a shell background job (e.g. nohup ./python -m test -j8 &), POSIX shells set SIGINT to SIG_IGN and Python does not install its default SIGINT handler. Then _thread.interrupt_main() is a no-op (PyErr_SetInterruptEx() does nothing when the handler is SIG_IGN or SIG_DFL) and asyncio.Runner does not install its own SIGINT handler, so tests relying on them in test_asyncio.test_runners and test_threading wait forever. In test_runners the event loop uses a mocked selector, so it busy-spins at 100% CPU while the Mock call history grows without bound (7 GiB in 20 minutes). There is no default test timeout, so the run never finishes.

Reproducer: sh -c 'trap "" INT; ./python -m test test.test_asyncio.test_runners'

Platform-independent (verified on Linux, FreeBSD, NetBSD). Note that GNU coreutils timeout masks the problem: it catches SIGINT itself, so a child it execs gets SIG_DFL restored.

Fix: restore the default SIGINT handler in regrtest's setup_process() when there is no Python-level handler.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions