Skip to content

Commit 5e96987

Browse files
committed
make loky a default on Windows and MacOS but not on Linux
1 parent 75a3274 commit 5e96987

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

adaptive/runner.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import inspect
66
import itertools
77
import pickle
8+
import platform
89
import time
910
import traceback
1011
import warnings
1112
from contextlib import suppress
1213

14+
import loky
15+
1316
from adaptive.notebook_integration import in_ipynb, live_info, live_plot
1417

1518
try:
@@ -33,22 +36,23 @@
3336
except ModuleNotFoundError:
3437
with_mpi4py = False
3538

36-
try:
37-
import loky
38-
39-
with_loky = True
40-
except ModuleNotFoundError:
41-
with_loky = False
4239

4340
with suppress(ModuleNotFoundError):
4441
import uvloop
4542

4643
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
4744

4845

49-
_default_executor = (
50-
loky.get_reusable_executor if with_loky else concurrent.ProcessPoolExecutor
51-
)
46+
if platform.system() == "Linux":
47+
_default_executor = concurrent.ProcessPoolExecutor
48+
else:
49+
# On Windows and MacOS functions, the __main__ module must be
50+
# importable by worker subprocesses. This means that
51+
# ProcessPoolExecutor will not work in the interactive interpreter.
52+
# On Linux the whole environment is forked, so the issue does
53+
# not appear.
54+
# See https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor
55+
_default_executor = loky.get_reusable_executor
5256

5357

5458
class BaseRunner(metaclass=abc.ABCMeta):
@@ -814,7 +818,7 @@ def _get_ncores(ex):
814818
ex, (concurrent.ProcessPoolExecutor, concurrent.ThreadPoolExecutor)
815819
):
816820
return ex._max_workers # not public API!
817-
elif with_loky and isinstance(ex, loky.reusable_executor._ReusablePoolExecutor):
821+
elif isinstance(ex, loky.reusable_executor._ReusablePoolExecutor):
818822
return ex._max_workers # not public API!
819823
elif isinstance(ex, SequentialExecutor):
820824
return 1

adaptive/tests/test_runner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
stop_after,
1616
with_distributed,
1717
with_ipyparallel,
18-
with_loky,
1918
)
2019

2120

@@ -139,7 +138,6 @@ def test_distributed_executor():
139138
assert learner.npoints > 0
140139

141140

142-
@pytest.mark.skipif(not with_loky, reason="loky not installed")
143141
def test_loky_executor(loky_executor):
144142
learner = Learner1D(lambda x: x, (-1, 1))
145143
BlockingRunner(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_version_and_cmdclass(package_name):
3030
"sortedcontainers >= 2.0",
3131
"atomicwrites",
3232
"cloudpickle",
33+
"loky >= 2.9",
3334
]
3435

3536
extras_require = {
@@ -55,7 +56,6 @@ def get_version_and_cmdclass(package_name):
5556
"dill",
5657
"distributed",
5758
"ipyparallel>=6.2.5", # because of https://github.com/ipython/ipyparallel/issues/404
58-
"loky",
5959
"scikit-optimize>=0.8.1", # because of https://github.com/scikit-optimize/scikit-optimize/issues/931
6060
"wexpect" if os.name == "nt" else "pexpect",
6161
],

0 commit comments

Comments
 (0)