Skip to content

Multiprocessing spawn processes with the same __name__ #2045

Open
@AGPX

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.

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