Skip to content

gh-157216: Document that forkserver preload skips deferred imports - #157237

Open
mohsen-rahmati-dev wants to merge 1 commit into
python:mainfrom
mohsen-rahmati-dev:docs-gh-157216
Open

gh-157216: Document that forkserver preload skips deferred imports#157237
mohsen-rahmati-dev wants to merge 1 commit into
python:mainfrom
mohsen-rahmati-dev:docs-gh-157216

Conversation

@mohsen-rahmati-dev

Copy link
Copy Markdown

The current set_forkserver_preload() entry says the named modules' "already imported state is inherited by forked processes", but doesn't say what happens to a module that a preloaded module imports inside a function body rather than at module level. Those are not imported in the forkserver process, so each child imports them privately on first use.

This adds a paragraph after the opening description: module-level imports are inherited (transitively), imports inside function bodies are not, with datetime.strptime() / _strptime as the example, and a note that calling such a function at the module level of a preloaded module puts the import in the forkserver.

Measurements, module counts and a reproducer are in gh-157216.

Docs-only, so no Misc/NEWS.d entry.

@python-cla-bot

python-cla-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34478900 | 📁 Comparing 8f57154 against main (9398655)

  🔍 Preview build  

1 file changed
± library/multiprocessing.html

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant