Skip to content

Commit 7247257

Browse files
authored
Merge pull request #120 from pyiron/future_exception
Handle Exceptions for Futures
2 parents 315c08f + 086e4e6 commit 7247257

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

pympipool/shared_functions/external_interfaces.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ def _execute_parallel_tasks_loop(interface, future_queue):
249249
elif "fn" in task_dict.keys() and "future" in task_dict.keys():
250250
f = task_dict.pop("future")
251251
if f.set_running_or_notify_cancel():
252-
f.set_result(interface.send_and_receive_dict(input_dict=task_dict))
252+
try:
253+
f.set_result(interface.send_and_receive_dict(input_dict=task_dict))
254+
except Exception as thread_exeception:
255+
f.set_exception(exception=thread_exeception)
256+
raise thread_exeception
253257
elif "fn" in task_dict.keys() and "init" in task_dict.keys():
254258
interface.send_dict(input_dict=task_dict)
255259

tests/test_worker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def test_executor_exception(self):
6262
with Executor(cores=1) as p:
6363
p.submit(raise_error)
6464

65+
def test_executor_exception_future(self):
66+
with self.assertRaises(RuntimeError):
67+
with Executor(cores=1) as p:
68+
fs = p.submit(raise_error)
69+
fs.result()
70+
6571
def test_pool_multi_core(self):
6672
with Executor(cores=2) as p:
6773
output = p.submit(mpi_funct, i=2)

0 commit comments

Comments
 (0)