Skip to content
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

Resolve multiprocessing warning, state Python 3.13 support #2246

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

rht
Copy link
Contributor

@rht rht commented Aug 25, 2024

This PR addresses a DeprecationWarning related to using fork() in multi-threaded processes, which can lead to deadlocks in the child processes when using Python's multiprocessing module. The 'spawn' method avoids the issues that arise from forking in a multi-threaded environment by starting a new Python interpreter process for each worker, which is safer and more compatible with modern systems.

It also adds the Python 3.13 qualifier to the pyproject.toml.

@EwoutH
Copy link
Member

EwoutH commented Aug 25, 2024

Thanks! I notice there's a warning that source directly from Python 3.13's multiprocessing, it might be nice to resolve that first.

tests/test_batch_run.py::test_batch_run_no_agent_reporters
  /opt/hostedtoolcache/Python/3.13.0-rc.1/x64/lib/python3.13/multiprocessing/popen_fork.py:67: DeprecationWarning: This process (pid=2042) is multi-threaded, use of fork() may lead to deadlocks in the child.
    self.pid = os.fork()

…t method

This commit addresses a DeprecationWarning related to using `fork()` in multi-threaded processes, which can lead to deadlocks in the child processes when using Python's `multiprocessing` module.

- Modified the `batch_run` function to set the multiprocessing start method to 'spawn' by default.
- The 'spawn' method avoids the issues that arise from forking in a multi-threaded environment by starting a new Python interpreter process for each worker, which is safer and more compatible with modern systems.
- This change ensures that the warning related to multi-threading and `fork()` is resolved across all environments where multiprocessing is used.

The change is applied globally to ensure consistent behavior in both code execution and testing environments. The test suite should now run without issuing a DeprecationWarning, and the multiprocessing behavior will be more robust, especially in environments that rely on threads.
@EwoutH EwoutH added the maintenance Release notes label label Sep 6, 2024
@EwoutH EwoutH changed the title Update to state support for Python 3.13 Resolve multiprocessing warning, state Python 3.13 support Sep 6, 2024
Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning resolved, good to go!

@rht rht merged commit 046cd97 into projectmesa:main Sep 6, 2024
12 of 13 checks passed
@rht rht deleted the badge branch September 6, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants