Skip to content

Commit 6ffa512

Browse files
committed
PERF: Revert multiprocessing start method change introduced in Python 3.14
Refs: python/cpython#84559 Fixes CI failing on TestDocs.test_examples: ModuleNotFoundError: No module named '<run_path>'
1 parent 1af1dda commit 6ffa512

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

backtesting/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@
6767

6868
from . import lib # noqa: F401
6969
from ._plotting import set_bokeh_output # noqa: F401
70+
from ._util import try_
7071
from .backtesting import Backtest, Strategy # noqa: F401
7172

7273

7374
# Add overridable backtesting.Pool used for parallel optimization
7475
def Pool(processes=None, initializer=None, initargs=()):
7576
import multiprocessing as mp
77+
import sys
78+
# Revert performance related change in Python>=3.14
79+
if sys.platform.startswith('linux') and mp.get_start_method(allow_none=True) != 'fork':
80+
try_(lambda: mp.set_start_method('fork'))
7681
if mp.get_start_method() == 'spawn':
7782
import warnings
7883
warnings.warn(

backtesting/test/_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,10 +1039,13 @@ class TestDocs(TestCase):
10391039
DOCS_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'doc')
10401040

10411041
@unittest.skipUnless(os.path.isdir(DOCS_DIR), "docs dir doesn't exist")
1042+
@unittest.skipUnless(sys.platform.startswith('linux'), "test_examples requires mp.start_method=fork")
10421043
def test_examples(self):
1044+
import backtesting
10431045
examples = glob(os.path.join(self.DOCS_DIR, 'examples', '*.py'))
10441046
self.assertGreaterEqual(len(examples), 4)
1045-
with chdir(gettempdir()):
1047+
with chdir(gettempdir()), \
1048+
patch(backtesting, 'Pool', mp.get_context('fork').Pool):
10461049
for file in examples:
10471050
with self.subTest(example=os.path.basename(file)):
10481051
run_path(file)

0 commit comments

Comments
 (0)