-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
When a function returns a tuple with multiple items, we want to have the capability access the individual items separately:
from executorlib import SingleNodeExecutor
def test_function(i):
return "a", "b", i
with SingleNodeExecutor() as exe:
future = exe.submit(test_function, 15)
f1, f2, f3 = split(future=future, n=3)
print(f1.result(), f2.result(), f3.result())
This can be realized with the following split()
function:
from concurrent.futures import Future
class SplitFuture(Future):
def __init__(self, future: Future, selector: int):
super().__init__()
self._future = future
self._selector = selector
def cancel(self):
return self._future.cancel()
def cancelled(self):
return self._future.cancelled()
def running(self):
return self._future.running()
def done(self):
return self._future.done()
def add_done_callback(self, fn):
return self._future.add_done_callback(fn=fn)
def result(self, timeout=None):
return self._future.result(timeout=timeout)[self._selector]
def exception(self, timeout=None):
return self._future.exception(timeout=timeout)
def set_running_or_notify_cancel(self):
return self._future.set_running_or_notify_cancel()
def set_result(self, result):
return self._future.set_result(result=result)
def set_exception(self, exception):
return self._future.set_exception(exception=exception)
def split(future: Future, n: int):
return [SplitFuture(future=future, selector=i) for i in range(n)]
While this functionality is not yet implemented, it is sufficiently simple to be defined dynamically.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation