88import time
99import traceback
1010import warnings
11+ import abc
1112
1213from .notebook_integration import live_plot , live_info , in_ipynb
1314from .utils import timed
@@ -53,7 +54,7 @@ def _default_executor(*args, **kwargs):
5354 _default_executor_kwargs = {}
5455
5556
56- class BaseRunner :
57+ class BaseRunner ( metaclass = abc . ABCMeta ) :
5758 """Base class for runners that use `concurrent.futures.Executors`.
5859
5960 Parameters
@@ -241,6 +242,20 @@ def _cleanup(self):
241242 def failed (self ):
242243 """Set of points that failed ``runner.retries`` times."""
243244 return set (self .tracebacks ) - set (self .to_retry )
245+
246+ @abc .abstractmethod
247+ def elapsed_time (self ):
248+ """Return the total time elapsed since the runner
249+ was started.
250+
251+ Is called in `overhead`.
252+ """
253+ pass
254+
255+ @abc .abstractmethod
256+ def _submit (self , x ):
257+ """Is called in `_get_futures`."""
258+ pass
244259
245260
246261class BlockingRunner (BaseRunner ):
@@ -444,11 +459,6 @@ def goal(_):
444459 raise RuntimeError ('Cannot use an executor when learning an '
445460 'async function.' )
446461 self .executor .shutdown () # Make sure we don't shoot ourselves later
447- self ._submit = lambda x : self .ioloop .create_task (self .function (x ))
448- else :
449- self ._submit = functools .partial (self .ioloop .run_in_executor ,
450- self .executor ,
451- self .function )
452462
453463 self .task = self .ioloop .create_task (self ._run ())
454464 self .saving_task = None
@@ -458,6 +468,13 @@ def goal(_):
458468 "in a Jupyter notebook, remember to run "
459469 "'adaptive.notebook_extension()'" )
460470
471+ def _submit (self , 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 )
477+
461478 def status (self ):
462479 """Return the runner status as a string.
463480
0 commit comments