Skip to content

to_process.run_sync fails to set up __main__ in worker process when run from an entry point #1027

@ilia-kats

Description

@ilia-kats

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

AnyIO version

4.11

Python version

3.11

What happened?

I have a package with an entry point defined in pyproject.toml and I want to run a function in a worker process. The function imports dill, which raises

[snip]

  File "/data/ilia/envs/famo/lib/python3.11/site-packages/dill/_dill.py", line 80, in <module>
    import __main__ as _main_module
          ^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '__main__'

I've tried to debug this a bit, and it turns out that importlib.util.spec_from_file_location (used in the worker process to set up __main__) always returns None if the path does not end in .py or .pyc.

sys.modules["__main__"].__spec__ is also None in that case.

How can we reproduce the bug?

Write a small dummy package with an entry point defined in pyproject.toml that runs a function in a worker process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions