Skip to content

Commit eaab130

Browse files
committed
use a concurrent.ProcessPoolExecutor on Windows too
In 890f84c I wrote that a 'concurrent.futures.ProcessPoolExecutor' doesn't work on Windows. However, it seems like it just works now.
1 parent ecd1f58 commit eaab130

File tree

2 files changed

+4
-40
lines changed

2 files changed

+4
-40
lines changed

adaptive/runner.py

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import asyncio
33
import concurrent.futures as concurrent
44
import inspect
5-
import os
65
import pickle
76
import sys
87
import time
@@ -39,30 +38,6 @@
3938
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
4039

4140

42-
if os.name == "nt":
43-
if with_distributed:
44-
_default_executor = distributed.Client
45-
_default_executor_kwargs = {"address": distributed.LocalCluster()}
46-
else:
47-
_windows_executor_msg = (
48-
"The default executor on Windows for 'adaptive.Runner' cannot "
49-
"be used because the package 'distributed' is not installed. "
50-
"Either install 'distributed' or explicitly specify an executor "
51-
"when using 'adaptive.Runner'."
52-
)
53-
54-
_default_executor_kwargs = {}
55-
56-
def _default_executor(*args, **kwargs):
57-
raise RuntimeError(_windows_executor_msg)
58-
59-
warnings.warn(_windows_executor_msg)
60-
61-
else:
62-
_default_executor = concurrent.ProcessPoolExecutor
63-
_default_executor_kwargs = {}
64-
65-
6641
class BaseRunner(metaclass=abc.ABCMeta):
6742
r"""Base class for runners that use `concurrent.futures.Executors`.
6843
@@ -76,9 +51,7 @@ class BaseRunner(metaclass=abc.ABCMeta):
7651
executor : `concurrent.futures.Executor`, `distributed.Client`,\
7752
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
7853
The executor in which to evaluate the function to be learned.
79-
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
80-
is used on Unix systems while on Windows a `distributed.Client`
81-
is used if `distributed` is installed.
54+
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`.
8255
ntasks : int, optional
8356
The number of concurrent function evaluations. Defaults to the number
8457
of cores available in `executor`.
@@ -298,9 +271,7 @@ class BlockingRunner(BaseRunner):
298271
executor : `concurrent.futures.Executor`, `distributed.Client`,\
299272
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
300273
The executor in which to evaluate the function to be learned.
301-
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
302-
is used on Unix systems while on Windows a `distributed.Client`
303-
is used if `distributed` is installed.
274+
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`.
304275
ntasks : int, optional
305276
The number of concurrent function evaluations. Defaults to the number
306277
of cores available in `executor`.
@@ -417,9 +388,7 @@ class AsyncRunner(BaseRunner):
417388
executor : `concurrent.futures.Executor`, `distributed.Client`,\
418389
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
419390
The executor in which to evaluate the function to be learned.
420-
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
421-
is used on Unix systems while on Windows a `distributed.Client`
422-
is used if `distributed` is installed.
391+
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`.
423392
ntasks : int, optional
424393
The number of concurrent function evaluations. Defaults to the number
425394
of cores available in `executor`.
@@ -773,7 +742,7 @@ def shutdown(self, wait=True):
773742

774743
def _ensure_executor(executor):
775744
if executor is None:
776-
executor = _default_executor(**_default_executor_kwargs)
745+
executor = concurrent.ProcessPoolExecutor()
777746

778747
if isinstance(executor, concurrent.Executor):
779748
return executor

setup.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22

3-
import os
43
import sys
54

65
from setuptools import find_packages, setup
@@ -31,10 +30,6 @@ def get_version_and_cmdclass(package_name):
3130
"atomicwrites",
3231
]
3332

34-
if os.name == "nt": # on Windows
35-
# distributed provides the default executor on Windows
36-
install_requires.append("distributed")
37-
3833
extras_require = {
3934
"notebook": [
4035
"ipython",

0 commit comments

Comments
 (0)