@@ -55,7 +55,7 @@ def _default_executor(*args, **kwargs):
55
55
56
56
57
57
class BaseRunner (metaclass = abc .ABCMeta ):
58
- """Base class for runners that use concurrent.futures.Executors.
58
+ """Base class for runners that use ` concurrent.futures.Executors` .
59
59
60
60
Parameters
61
61
----------
@@ -245,12 +245,16 @@ def failed(self):
245
245
246
246
@abc .abstractmethod
247
247
def elapsed_time (self ):
248
- """Is called in 'overhead'."""
248
+ """Return the total time elapsed since the runner
249
+ was started.
250
+
251
+ Is called in `overhead`.
252
+ """
249
253
pass
250
254
251
255
@abc .abstractmethod
252
256
def _submit (self , x ):
253
- """Is called in ' _get_futures' ."""
257
+ """Is called in ` _get_futures` ."""
254
258
pass
255
259
256
260
@@ -455,11 +459,6 @@ def goal(_):
455
459
raise RuntimeError ('Cannot use an executor when learning an '
456
460
'async function.' )
457
461
self .executor .shutdown () # Make sure we don't shoot ourselves later
458
- self .__submit = lambda x : self .ioloop .create_task (self .function (x ))
459
- else :
460
- self .__submit = functools .partial (self .ioloop .run_in_executor ,
461
- self .executor ,
462
- self .function )
463
462
464
463
self .task = self .ioloop .create_task (self ._run ())
465
464
self .saving_task = None
@@ -470,7 +469,11 @@ def goal(_):
470
469
"'adaptive.notebook_extension()'" )
471
470
472
471
def _submit (self , x ):
473
- return self .__submit (x )
472
+ ioloop = self .ioloop
473
+ if inspect .iscoroutinefunction (self .learner .function ):
474
+ return ioloop .create_task (self .function (x ))
475
+ else :
476
+ return ioloop .run_in_executor (self .executor , self .function , x )
474
477
475
478
def status (self ):
476
479
"""Return the runner status as a string.
0 commit comments