From 0f85d3abd1cb0eddf195dec0deabd6d0dd97d268 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Fri, 10 Apr 2020 16:09:07 +0200 Subject: [PATCH] fix test_default_executor --- adaptive/runner.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/adaptive/runner.py b/adaptive/runner.py index da24d3009..9a8a9b1a5 100644 --- a/adaptive/runner.py +++ b/adaptive/runner.py @@ -49,6 +49,11 @@ asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) +_default_executor = ( + loky.get_reusable_executor if with_loky else concurrent.ProcessPoolExecutor +) + + class BaseRunner(metaclass=abc.ABCMeta): r"""Base class for runners that use `concurrent.futures.Executors`. @@ -478,7 +483,11 @@ def __init__( def goal(_): return False - if executor is None and not inspect.iscoroutinefunction(learner.function): + if ( + executor is None + and _default_executor is concurrent.ProcessPoolExecutor + and not inspect.iscoroutinefunction(learner.function) + ): try: pickle.dumps(learner.function) except pickle.PicklingError: @@ -756,13 +765,6 @@ def shutdown(self, wait=True): pass -def _default_executor(): - if with_loky: - return loky.get_reusable_executor() - else: - return concurrent.ProcessPoolExecutor() - - def _ensure_executor(executor): if executor is None: executor = _default_executor()