Skip to content

Commit 9367bc8

Browse files
authored
gh-157216: Clarify that set_forkserver_preload() does not cover lazy imports
Clarify behavior of module preloading in forkserver.
1 parent 52ffffe commit 9367bc8

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Doc/library/multiprocessing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,14 @@ Miscellaneous
12451245
For this to work, it must be called before the forkserver process has been
12461246
launched (before creating a :class:`Pool` or starting a :class:`Process`).
12471247

1248+
Only modules directly imported at top level by *module_names* are preloaded.
1249+
If a preloaded module lazily imports dependencies inside functions or methods
1250+
(for example, :meth:`datetime.datetime.strptime` importing ``_strptime`` on
1251+
its first invocation), those dependencies are not loaded into the forkserver
1252+
process and will instead be imported separately in each child process upon
1253+
first use. To inherit those as well, call such functions at module level
1254+
within a preloaded module.
1255+
12481256
The *on_error* parameter controls how :exc:`ImportError` exceptions during
12491257
module preloading are handled: ``"ignore"`` (default) silently ignores
12501258
failures, ``"warn"`` causes the forkserver subprocess to emit an

0 commit comments

Comments
 (0)