Browse code

fix test_default_executor

Bas Nijholt authored on 10/04/2020 16:09:07
Showing 1 changed files
... ...
@@ -49,6 +49,11 @@ with suppress(ModuleNotFoundError):
49 49
     asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
50 50
 
51 51
 
52
+_default_executor = (
53
+    loky.get_reusable_executor if with_loky else concurrent.ProcessPoolExecutor
54
+)
55
+
56
+
52 57
 class BaseRunner(metaclass=abc.ABCMeta):
53 58
     r"""Base class for runners that use `concurrent.futures.Executors`.
54 59
 
... ...
@@ -478,7 +483,11 @@ class AsyncRunner(BaseRunner):
478 483
             def goal(_):
479 484
                 return False
480 485
 
481
-        if executor is None and not inspect.iscoroutinefunction(learner.function):
486
+        if (
487
+            executor is None
488
+            and _default_executor is concurrent.ProcessPoolExecutor
489
+            and not inspect.iscoroutinefunction(learner.function)
490
+        ):
482 491
             try:
483 492
                 pickle.dumps(learner.function)
484 493
             except pickle.PicklingError:
... ...
@@ -756,13 +765,6 @@ class SequentialExecutor(concurrent.Executor):
756 765
         pass
757 766
 
758 767
 
759
-def _default_executor():
760
-    if with_loky:
761
-        return loky.get_reusable_executor()
762
-    else:
763
-        return concurrent.ProcessPoolExecutor()
764
-
765
-
766 768
 def _ensure_executor(executor):
767 769
     if executor is None:
768 770
         executor = _default_executor()