Skip to content

Commit

Permalink
use a concurrent.ProcessPoolExecutor on Windows too
Browse files Browse the repository at this point in the history
In 890f84c I wrote that a 'concurrent.futures.ProcessPoolExecutor' doesn't work on Windows.
However, it seems like it just works now.
  • Loading branch information
basnijholt committed Dec 17, 2019
1 parent ecd1f58 commit eaab130
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
39 changes: 4 additions & 35 deletions adaptive/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import concurrent.futures as concurrent
import inspect
import os
import pickle
import sys
import time
Expand Down Expand Up @@ -39,30 +38,6 @@
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())


if os.name == "nt":
if with_distributed:
_default_executor = distributed.Client
_default_executor_kwargs = {"address": distributed.LocalCluster()}
else:
_windows_executor_msg = (
"The default executor on Windows for 'adaptive.Runner' cannot "
"be used because the package 'distributed' is not installed. "
"Either install 'distributed' or explicitly specify an executor "
"when using 'adaptive.Runner'."
)

_default_executor_kwargs = {}

def _default_executor(*args, **kwargs):
raise RuntimeError(_windows_executor_msg)

warnings.warn(_windows_executor_msg)

else:
_default_executor = concurrent.ProcessPoolExecutor
_default_executor_kwargs = {}


class BaseRunner(metaclass=abc.ABCMeta):
r"""Base class for runners that use `concurrent.futures.Executors`.
Expand All @@ -76,9 +51,7 @@ class BaseRunner(metaclass=abc.ABCMeta):
executor : `concurrent.futures.Executor`, `distributed.Client`,\
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
The executor in which to evaluate the function to be learned.
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
is used on Unix systems while on Windows a `distributed.Client`
is used if `distributed` is installed.
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`.
ntasks : int, optional
The number of concurrent function evaluations. Defaults to the number
of cores available in `executor`.
Expand Down Expand Up @@ -298,9 +271,7 @@ class BlockingRunner(BaseRunner):
executor : `concurrent.futures.Executor`, `distributed.Client`,\
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
The executor in which to evaluate the function to be learned.
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
is used on Unix systems while on Windows a `distributed.Client`
is used if `distributed` is installed.
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`.
ntasks : int, optional
The number of concurrent function evaluations. Defaults to the number
of cores available in `executor`.
Expand Down Expand Up @@ -417,9 +388,7 @@ class AsyncRunner(BaseRunner):
executor : `concurrent.futures.Executor`, `distributed.Client`,\
`mpi4py.futures.MPIPoolExecutor`, or `ipyparallel.Client`, optional
The executor in which to evaluate the function to be learned.
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`
is used on Unix systems while on Windows a `distributed.Client`
is used if `distributed` is installed.
If not provided, a new `~concurrent.futures.ProcessPoolExecutor`.
ntasks : int, optional
The number of concurrent function evaluations. Defaults to the number
of cores available in `executor`.
Expand Down Expand Up @@ -773,7 +742,7 @@ def shutdown(self, wait=True):

def _ensure_executor(executor):
if executor is None:
executor = _default_executor(**_default_executor_kwargs)
executor = concurrent.ProcessPoolExecutor()

if isinstance(executor, concurrent.Executor):
return executor
Expand Down
5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import os
import sys

from setuptools import find_packages, setup
Expand Down Expand Up @@ -31,10 +30,6 @@ def get_version_and_cmdclass(package_name):
"atomicwrites",
]

if os.name == "nt": # on Windows
# distributed provides the default executor on Windows
install_requires.append("distributed")

extras_require = {
"notebook": [
"ipython",
Expand Down

0 comments on commit eaab130

Please sign in to comment.