Skip to content

gh-103758: Add test for multiple os.register_at_fork registrations - #159705

Open
plfj wants to merge 1 commit into
python:mainfrom
plfj:gh-103758-fork-order
Open

plfj wants to merge 1 commit into
python:mainfrom
plfj:gh-103758-fork-order

Conversation

@plfj

@plfj plfj commented Oct 19, 2026

Copy link
Copy Markdown

Fixes gh-103758.
Supersedes and closes gh-103759.

Summary

Adds a regression test in Lib/test/test_os/test_posix.py to verify that registering callbacks multiple times via os.register_at_fork() correctly preserves both old and newly registered handlers across successive forks.

Specifically, it verifies:

  • before handlers execute in LIFO (reverse) order.
  • after_in_parent handlers execute in FIFO order.
  • after_in_child handlers execute in FIFO order.
  • Handlers registered after an earlier fork accumulate and run alongside previous generations in subsequent forks.

Note on Previous Work

This issue was originally reported by @itsankitkp with an initial implementation in #103759.

This PR supersedes #103759 by addressing reliability issues in the earlier attempt:

  • Eliminates multi-process race conditions on a shared pipe by validating events per-process in memory.
  • Eliminates pipe token-starvation deadlocks on child exit.
  • Uses test.support.wait_process to reap child processes cleanly and verify exit status.

Credit is attributed to the original author via the commit trailer (Co-authored-by).

Checklist

  • Tested locally with ./python -m test -v test_os.test_posix
  • All required CI checks passed cleanly
  • No NEWS entry required (test-only change as per Devguide)

…ross forks

Add a test verifying that handlers registered after an earlier fork()
run together with previously registered handlers in subsequent forks,
preserving LIFO order for 'before' handlers and FIFO order for 'after_*'
handlers.

Co-authored-by: Ankit Kumar Pandey <itsankitkp@users.noreply.github.com>
@python-cla-bot

python-cla-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 19, 2026
@bedevere-app bedevere-app Bot added awaiting review tests Tests in the Lib/test dir labels Oct 19, 2026
@bedevere-app

bedevere-app Bot commented Oct 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@plfj
plfj force-pushed the gh-103758-fork-order branch from 5e815cc to 6f97f0a Compare October 19, 2026 15:30
@bedevere-app

bedevere-app Bot commented Oct 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test case in os.register_at_fork to verify new and old forkers get executed

1 participant