Skip to content

forkserver.set_forkserver_preload() silent preload import failures when sys.path is required #117378

Closed

Description

@doublex

Bug report

Bug description:

Bug in def main(): https://github.com/python/cpython/blob/main/Lib/multiprocessing/forkserver.py#L167

The param sys_path is ignored. Result: ModuleNotFoundError for preloaded modules.

a) Using sys_path fixes this issue
b) Maybe better remove "pass" and report and error to simplify problem solving

    if preload:
        if '__main__' in preload and main_path is not None:
            process.current_process()._inheriting = True
            try:
                spawn.import_main_path(main_path)
            finally:
                del process.current_process()._inheriting
+        if sys_path:
+            sys.path = sys_path
        for modname in preload:
            try:
                __import__(modname)
            except ImportError:
-                pass
+                warnings.warn('forkserver: preloading module failed %s' % modname)

CPython versions tested on:

3.12

Operating systems tested on:

No response

Linked PRs

Activity

  1. self-assigned this
    on Nov 7, 2024
  2. added a commit that references this issue on Nov 7, 2024
  3. gpshead commented on Nov 7, 2024

    @gpshead
    Member

    Thanks! This is an ironic bug. It has been there from the start for the forkserver. I suspect in a lot of environments it just didn't matter as the default path or PYTHONPATH from the environment was correct. But I can easily imagine situations where this would defeat the purpose of preloading or even potentially cause subtle bugs based on "" vs the absolute path determined at parent multiprocessing import time being in that preload's sys.path.

  4. moved this to In Progress in Multiprocessing issueson Nov 7, 2024
  5. doublex commented on Nov 7, 2024

    @doublex
    Author

    @gpshead
    Thank you very much for your efforts!

  6. added a commit that references this issue on Nov 9, 2024
  7. added a commit that references this issue on Nov 9, 2024
  8. added 2 commits that reference this issue on Nov 9, 2024
  9. 6 remaining items

  10. added 3 commits that reference this issue on Nov 10, 2024
  11. added 2 commits that reference this issue on Nov 11, 2024
  12. added 2 commits that reference this issue on Nov 11, 2024
  13. added 3 commits that reference this issue on Dec 8, 2024
  14. added 3 commits that reference this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions