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 to Lib/test/test_os/test_posix.py to ensure multiple callbacks are handled correctly when registering multiple callbacks with os.register_at_fork().

The test ensures that:

  • before callbacks are called in reverse order (LIFO).
  • after_in_parent callbacks are called in order (FIFO).
  • after_in_child callbacks are called in order (FIFO).
  • Callbacks registered after forks will be registered and called alongside previous generations.

Notes

Original issue raised by @itsankitkp. Original code can be seen in #103759.

This PR replaces #103759 by addressing reliability concerns from the earlier attempt:

  • Ensures there are no race conditions between processes by verifying events correctly in memory.
  • Avoids deadlocks due to pipe starvation on child exit.
  • All children are cleaned up with test.support.wait_process and their exit status checked.
  • Original author noted in the commit trailer.

Checklist

  • Tested locally: ./python -m test -v test_os.test_posix
  • All CI checks passed
  • No NEWS entry: Test-only change (see Devguide)

@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.

@plfj
plfj force-pushed the gh-103758-fork-order branch from 6f97f0a to df98a97 Compare October 20, 2026 10:35
@bedevere-app

bedevere-app Bot commented Oct 20, 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 3 times, most recently from c9d2617 to a7dd836 Compare October 20, 2026 16:20
@bedevere-app

bedevere-app Bot commented Oct 20, 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.

…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>
@plfj
plfj force-pushed the gh-103758-fork-order branch from a7dd836 to e177458 Compare October 24, 2026 17:10
@bedevere-app

bedevere-app Bot commented Oct 24, 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