Skip to content

Commit

Permalink
Use forkserver instead of fork for multiprocessing
Browse files Browse the repository at this point in the history
Polars gives warnings if using fork.
preexec_fn in create_subprocess_exec is unsafe using fork.
python 3.14 will set forkserver as default on linux/bsd.
  • Loading branch information
JHolba committed Dec 2, 2024
1 parent b5a1805 commit 3ec52e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import locale
import logging
import logging.config
import multiprocessing
import os
import re
import resource
Expand Down Expand Up @@ -706,4 +707,9 @@ def main() -> None:


if __name__ == "__main__":
if (
sys.platform == "linux"
and multiprocessing.get_start_method(allow_none=True) != "forkserver"
):
multiprocessing.set_start_method("forkserver")
main()
10 changes: 10 additions & 0 deletions tests/ert/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fileinput
import logging
import multiprocessing
import os
import resource
import shutil
Expand Down Expand Up @@ -485,3 +486,12 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

monkeypatch.setattr("ert.cli.main.EvaluatorServerConfig", MockESConfig)


@pytest.fixture(scope="session", autouse=True)
def set_multiprocessing_method():
if (
sys.platform == "linux"
and multiprocessing.get_start_method(allow_none=True) != "forkserver"
):
multiprocessing.set_start_method("forkserver")

0 comments on commit 3ec52e2

Please sign in to comment.