Skip to content

Commit 98b2269

Browse files
committed
make '_submit' a method
1 parent 59877e6 commit 98b2269

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

adaptive/runner.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _default_executor(*args, **kwargs):
5555

5656

5757
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`.
5959
6060
Parameters
6161
----------
@@ -245,12 +245,16 @@ def failed(self):
245245

246246
@abc.abstractmethod
247247
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+
"""
249253
pass
250254

251255
@abc.abstractmethod
252256
def _submit(self, x):
253-
"""Is called in '_get_futures'."""
257+
"""Is called in `_get_futures`."""
254258
pass
255259

256260

@@ -455,11 +459,6 @@ def goal(_):
455459
raise RuntimeError('Cannot use an executor when learning an '
456460
'async function.')
457461
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)
463462

464463
self.task = self.ioloop.create_task(self._run())
465464
self.saving_task = None
@@ -470,7 +469,11 @@ def goal(_):
470469
"'adaptive.notebook_extension()'")
471470

472471
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)
474477

475478
def status(self):
476479
"""Return the runner status as a string.

0 commit comments

Comments
 (0)