Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

test_forkserver_sigkill: join() can return before the child sets the event

Closed Beginner friendly
#160,295 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
71/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing

Research direction

Read Lib/test/_test_multiprocessing.py, especially check_forkserver_death() and test_forkserver_sigkill; the failure is that join() can return before the child sets the event after the forkserver is killed. Update the event check to wait with a timeout, then run the focused forkserver test. Done means the test allows the child time to set the event and still checks the expected exit code.

Written by the indexing model from the issue text.

Description

tests topic-multiprocessing type-bug

Bug report

Bug description:

test_forkserver_sigkill failed once during a full ./python.exe -m test -j0 run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e512b30). The load average was around 65 at the time. It passes when run on its own.

test test.test_multiprocessing_forkserver.test_processes failed -- Traceback (most recent call last):
  File "Lib/test/_test_multiprocessing.py", line 1007, in test_forkserver_sigkill
    self.check_forkserver_death(signal.SIGKILL)
  File "Lib/test/_test_multiprocessing.py", line 997, in check_forkserver_death
    self.assertTrue(evt.is_set())
AssertionError: False is not true

(paths shortened)

This is the same failure as gh-78221 (bpo-34040). It was worked around in 2018 by shortening the child's delay relative to the parent's sleep (07888e1cce), but the race is still there.

check_forkserver_death() kills the forkserver right after starting the first process. After a SIGKILL, the forkserver can no longer report that child's exit status: proc.join() gets EOF on the status pipe, and Popen.poll() in Lib/multiprocessing/popen_forkserver.py sets returncode to 255 immediately. The child may still be running at that point. The test then checks evt.is_set(), which only passes if the child has set the event by then (within the 1 second sleep plus the time proc2 takes). The next line already accepts exit code 255 for the case where the forkserver was killed.

SIGINT is not affected: the forkserver ignores it, stays alive and reports the real exit code.

To reproduce it reliably, stop the first child with SIGSTOP for a few seconds after killing the forkserver:

Reproducer
import multiprocessing as mp, os, signal, threading, time
from multiprocessing.forkserver import _forkserver

def sleep_and_set(evt, delay=0.0):
    time.sleep(delay)
    evt.set()

if __name__ == '__main__':
    mp.set_start_method('forkserver')
    _forkserver.ensure_running()
    evt = mp.Event()
    proc = mp.Process(target=sleep_and_set, args=(evt, 0.5))
    proc.start()
    os.kill(_forkserver._forkserver_pid, signal.SIGKILL)
    # Simulate the child not getting CPU time for 3 seconds.
    os.kill(proc.pid, signal.SIGSTOP)
    threading.Timer(3.0, os.kill, (proc.pid, signal.SIGCONT)).start()
    time.sleep(1.0)
    proc.join()
    print(proc.exitcode, evt.is_set())  # 255 False
    print(evt.wait(60))                 # True: the child did run, later

Waiting for the event with a timeout, instead of checking it right after join(), fixes it.

The same code is in 3.13, 3.14 and 3.15.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS, Linux

Linked PRs
  • gh-160296
Dominant language
Python
Stars
77.8k
Forks
37.7k
Avg merge
12h 14m
Merged PRs (30d)
729

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.