Skip to content

Multiprocessing spawn processes with the same __name__ #2045

Description

@AGPX

I have a code that use the multiprocessing module to spawn new processes like this:

...
ctx = multiprocessing.get_context('spawn')
process = ctx.Process(target=_worker, args=args, daemon=True)
process.start()
...

I have to distinguish them from the main execution, through the code:

if __name__ == '__main__':
...

If I run this script from command line (running Python.exe), the __name__ is different for each process. When I run it through the py::exec, the __name__ is always __main__. How can I overcome this issue? Thanks.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions