Skip to content

Commit a456a6b

Browse files
committed
FIX: Ensure same logic
1 parent b1a8f4c commit a456a6b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

pydra/engine/core.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,6 @@ def prepare_run_task(self, rerun):
463463
# retrieve cached results
464464
if not (rerun or self.task_rerun):
465465
result = self.result()
466-
if result is not None and not result.errored:
467-
return result
468466
# adding info file with the checksum in case the task was cancelled
469467
# and the lockfile has to be removed
470468
with open(self.cache_dir / f"{self.uid}_info.json", "w") as jsonfile:
@@ -493,12 +491,17 @@ def _run(self, rerun=False, **kwargs):
493491
# Eagerly retrieve cached - see scenarios in __init__()
494492
self.hooks.pre_run(self)
495493
with SoftFileLock(lockfile):
494+
if not (rerun or self.task_rerun):
495+
result = self.result()
496+
if result is not None and not result.errored:
497+
return result
496498
cwd = os.getcwd()
497499
result = self.prepare_run_task(rerun)
500+
orig_outdir = self.output_dir
498501
try:
499502
self.audit.monitor()
500503
self._run_task()
501-
result.output = self._collect_outputs(output_dir=self.output_dir)
504+
result.output = self._collect_outputs(output_dir=orig_outdir)
502505
except Exception:
503506
etype, eval, etr = sys.exc_info()
504507
traceback = format_exception(etype, eval, etr)
@@ -508,14 +511,14 @@ def _run(self, rerun=False, **kwargs):
508511
finally:
509512
self.hooks.post_run_task(self, result)
510513
self.audit.finalize_audit(result)
511-
save(self.output_dir, result=result, task=self)
514+
save(orig_outdir, result=result, task=self)
512515
self.output_ = None
513516
# removing the additional file with the chcksum
514517
(self.cache_dir / f"{self.uid}_info.json").unlink()
515518
# # function etc. shouldn't change anyway, so removing
516-
self._orig_inputs = dict(
517-
(k, v) for (k, v) in self._orig_inputs.items() if not k.startswith("_")
518-
)
519+
self._orig_inputs = {
520+
k: v for k, v in self._orig_inputs.items() if not k.startswith("_")
521+
}
519522
self.inputs = attr.evolve(self.inputs, **self._orig_inputs)
520523
# no need to propagate this
521524
del self._orig_inputs
@@ -1056,8 +1059,13 @@ async def _run(self, submitter=None, rerun=False, **kwargs):
10561059
lockfile = self.cache_dir / (self.checksum + ".lock")
10571060
self.hooks.pre_run(self)
10581061
async with PydraFileLock(lockfile):
1062+
if not (rerun or self.task_rerun):
1063+
result = self.result()
1064+
if result is not None and not result.errored:
1065+
return result
10591066
cwd = os.getcwd()
10601067
result = self.prepare_run_task(rerun)
1068+
orig_outdir = self.output_dir
10611069
try:
10621070
self.audit.monitor()
10631071
await self._run_task(submitter, rerun=rerun)
@@ -1072,7 +1080,7 @@ async def _run(self, submitter=None, rerun=False, **kwargs):
10721080
finally:
10731081
self.hooks.post_run_task(self, result)
10741082
self.audit.finalize_audit(result=result)
1075-
save(self.output_dir, result=result, task=self)
1083+
save(orig_outdir, result=result, task=self)
10761084
# removing the additional file with the chcksum
10771085
(self.cache_dir / f"{self.uid}_info.json").unlink()
10781086
os.chdir(cwd)

0 commit comments

Comments
 (0)