Skip to content

Fixed dataset combination issue in CycleGAN fro spawn process in windows #1691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JVSCHANDRADITHYA
Copy link

Bug Description

The original script using multiprocessing works fine on Linux/macOS but causes an infinite recursion error on Windows. This happens because Windows uses the "spawn" method for creating new processes, which re-imports the script when a new process is spawned. As a result, every subprocess starts executing the entire script again, leading to an infinite loop of process creation.
Cause of the Bug

Windows does not support forking processes like Linux/macOS.
When the script calls Pool.apply_async() or Pool.map(), Windows spawns a new process and re-imports the script.
Since Pool() is created at the top level (outside if __name__ == "__main__":), the new process also creates another pool, which spawns more processes, repeating infinitely.

Fix

To prevent this infinite loop, we wrap the multiprocessing logic inside if __name__ == "__main__":. This ensures that the pool is only created when the script is executed directly and not when a subprocess re-imports it.

How This Fix Works:

Prevents Recursive Execution:
    When Windows spawns a new process, it re-runs the entire script.
    The `if __name__ == "__main__":` guard ensures that Pool() is only created in the main execution context.

Solves Import Loops:
    Without this guard, the script would keep launching new processes indefinitely because each subprocess would re-run the script and spawn more subprocesses.

Windows-Specific Handling (freeze_support()):
    Required in some cases, especially for packaged executables (e.g., when using PyInstaller).

Does This Apply to Your Script?

If you’re running the script on Windows, yes, you need to wrap multiprocessing-related code inside `if __name__ == "__main__":`.
On Linux/macOS, this isn't an issue because they use "fork" instead of "spawn."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant