Skip to content

Commit 48d652b

Browse files
authored
Replace an always-true if with an assert (#4002)
The "else" case of the erstwhile-if statement was not defined properly: What are the circumstances and behaviour if an exec_fu is not set by this point? All don't-launch-yet behaviour is covered by `return` statements earlier on and the second part of the method should always proceed with making an exec_fu of some kind. # Changed Behaviour none ## Type of change - Code maintenance/cleanup
1 parent e1e4bd1 commit 48d652b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

parsl/dataflow/dflow.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def _launch_if_ready_async(self, task_record: TaskRecord) -> None:
615615
_launch_if_ready will launch the specified task, if it is ready
616616
to run (for example, without dependencies, and in pending state).
617617
"""
618-
exec_fu = None
618+
exec_fu: Future
619619

620620
task_id = task_record['id']
621621
with task_record['task_launch_lock']:
@@ -663,19 +663,19 @@ def _launch_if_ready_async(self, task_record: TaskRecord) -> None:
663663
exec_fu.set_exception(DependencyError(exceptions_tids,
664664
task_id))
665665

666-
if exec_fu:
667-
assert isinstance(exec_fu, Future)
668-
try:
669-
exec_fu.add_done_callback(partial(self.handle_exec_update, task_record))
670-
except Exception:
671-
# this exception is ignored here because it is assumed that exception
672-
# comes from directly executing handle_exec_update (because exec_fu is
673-
# done already). If the callback executes later, then any exception
674-
# coming out of the callback will be ignored and not propate anywhere,
675-
# so this block attempts to keep the same behaviour here.
676-
logger.error("add_done_callback got an exception which will be ignored", exc_info=True)
677-
678-
task_record['exec_fu'] = exec_fu
666+
assert isinstance(exec_fu, Future), "Every code path leading here needs to define exec_fu"
667+
668+
try:
669+
exec_fu.add_done_callback(partial(self.handle_exec_update, task_record))
670+
except Exception:
671+
# this exception is ignored here because it is assumed that exception
672+
# comes from directly executing handle_exec_update (because exec_fu is
673+
# done already). If the callback executes later, then any exception
674+
# coming out of the callback will be ignored and not propate anywhere,
675+
# so this block attempts to keep the same behaviour here.
676+
logger.error("add_done_callback got an exception which will be ignored", exc_info=True)
677+
678+
task_record['exec_fu'] = exec_fu
679679

680680
def launch_task(self, task_record: TaskRecord) -> Future:
681681
"""Handle the actual submission of the task to the executor layer.

0 commit comments

Comments
 (0)