From 60e228cf4e770197d4605ca818c7568aa24edcc6 Mon Sep 17 00:00:00 2001 From: rht Date: Sun, 25 Aug 2024 09:40:14 -0400 Subject: [PATCH 1/2] Update to state support for Python 3.13 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index ee2dec72631..854d5a3af61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Development Status :: 3 - Alpha", From 85619de9d5a4ce21422ae2784cf5896431b0b622 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Fri, 6 Sep 2024 15:39:52 +0200 Subject: [PATCH 2/2] Resolve multiprocessing deadlock warning by switching to 'spawn' start 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. --- mesa/batchrunner.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mesa/batchrunner.py b/mesa/batchrunner.py index 80ba23cafdf..e34193c3fd7 100644 --- a/mesa/batchrunner.py +++ b/mesa/batchrunner.py @@ -1,4 +1,5 @@ import itertools +import multiprocessing from collections.abc import Iterable, Mapping from functools import partial from multiprocessing import Pool @@ -8,6 +9,8 @@ from mesa.model import Model +multiprocessing.set_start_method("spawn", force=True) + def batch_run( model_cls: type[Model],