From 9367bc8e34872ccce03614ee8256f8a83ed36ec1 Mon Sep 17 00:00:00 2001 From: Vimal Sahani Date: Thu, 10 Sep 2026 00:02:10 +0530 Subject: [PATCH] gh-157216: Clarify that set_forkserver_preload() does not cover lazy imports Clarify behavior of module preloading in forkserver. --- Doc/library/multiprocessing.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index bedea46cb16d60d..902d18f30a6c3c5 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1245,6 +1245,14 @@ Miscellaneous For this to work, it must be called before the forkserver process has been launched (before creating a :class:`Pool` or starting a :class:`Process`). + Only modules directly imported at top level by *module_names* are preloaded. + If a preloaded module lazily imports dependencies inside functions or methods + (for example, :meth:`datetime.datetime.strptime` importing ``_strptime`` on + its first invocation), those dependencies are not loaded into the forkserver + process and will instead be imported separately in each child process upon + first use. To inherit those as well, call such functions at module level + within a preloaded module. + The *on_error* parameter controls how :exc:`ImportError` exceptions during module preloading are handled: ``"ignore"`` (default) silently ignores failures, ``"warn"`` causes the forkserver subprocess to emit an