Skip to content

Commit 5cbca66

Browse files
committed
FIX: Ensure output_dir is not recalculated
1 parent 36ad2df commit 5cbca66

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

pydra/engine/core.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def _modify_inputs(self):
463463
self.inputs = attr.evolve(self.inputs, **modified_inputs)
464464
return orig_inputs
465465

466-
def _populate_filesystem(self):
466+
def _populate_filesystem(self, checksum, output_dir):
467467
"""
468468
Invoked immediately after the lockfile is generated, this function:
469469
- Creates the cache file
@@ -475,16 +475,18 @@ def _populate_filesystem(self):
475475
# adding info file with the checksum in case the task was cancelled
476476
# and the lockfile has to be removed
477477
with open(self.cache_dir / f"{self.uid}_info.json", "w") as jsonfile:
478-
json.dump({"checksum": self.checksum}, jsonfile)
479-
if not self.can_resume and self.output_dir.exists():
480-
shutil.rmtree(self.output_dir)
481-
self.output_dir.mkdir(parents=False, exist_ok=self.can_resume)
478+
json.dump({"checksum": checksum}, jsonfile)
479+
if not self.can_resume and output_dir.exists():
480+
shutil.rmtree(output_dir)
481+
output_dir.mkdir(parents=False, exist_ok=self.can_resume)
482482

483483
def _run(self, rerun=False, **kwargs):
484484
self.inputs = attr.evolve(self.inputs, **kwargs)
485485
self.inputs.check_fields_input_spec()
486486

487-
lockfile = self.cache_dir / (self.checksum + ".lock")
487+
checksum = self.checksum
488+
output_dir = self.output_dir
489+
lockfile = self.cache_dir / (checksum + ".lock")
488490
# Eagerly retrieve cached - see scenarios in __init__()
489491
self.hooks.pre_run(self)
490492
with SoftFileLock(lockfile):
@@ -493,27 +495,25 @@ def _run(self, rerun=False, **kwargs):
493495
if result is not None and not result.errored:
494496
return result
495497
cwd = os.getcwd()
496-
self._populate_filesystem()
498+
self._populate_filesystem(checksum, output_dir)
497499
orig_inputs = self._modify_inputs()
498-
# the output dir can be changed by _run_task (but should it??)
499-
orig_outdir = self.output_dir
500500
result = Result(output=None, runtime=None, errored=False)
501501
self.hooks.pre_run_task(self)
502-
self.audit.start_audit(odir=self.output_dir)
502+
self.audit.start_audit(odir=output_dir)
503503
try:
504504
self.audit.monitor()
505505
self._run_task()
506-
result.output = self._collect_outputs(output_dir=orig_outdir)
506+
result.output = self._collect_outputs(output_dir=output_dir)
507507
except Exception:
508508
etype, eval, etr = sys.exc_info()
509509
traceback = format_exception(etype, eval, etr)
510-
record_error(self.output_dir, error=traceback)
510+
record_error(output_dir, error=traceback)
511511
result.errored = True
512512
raise
513513
finally:
514514
self.hooks.post_run_task(self, result)
515515
self.audit.finalize_audit(result)
516-
save(orig_outdir, result=result, task=self)
516+
save(output_dir, result=result, task=self)
517517
self.output_ = None
518518
# removing the additional file with the chcksum
519519
(self.cache_dir / f"{self.uid}_info.json").unlink()
@@ -1056,35 +1056,36 @@ async def _run(self, submitter=None, rerun=False, **kwargs):
10561056
)
10571057
# creating connections that were defined after adding tasks to the wf
10581058
self._connect_and_propagate_to_tasks()
1059-
lockfile = self.cache_dir / (self.checksum + ".lock")
1059+
1060+
checksum = self.checksum
1061+
output_dir = self.output_dir
1062+
lockfile = self.cache_dir / (checksum + ".lock")
10601063
self.hooks.pre_run(self)
10611064
async with PydraFileLock(lockfile):
10621065
if not (rerun or self.task_rerun):
10631066
result = self.result()
10641067
if result is not None and not result.errored:
10651068
return result
10661069
cwd = os.getcwd()
1067-
self._populate_filesystem()
1068-
# the output dir can be changed by _run_task (but should it??)
1069-
orig_outdir = self.output_dir
1070+
self._populate_filesystem(checksum, output_dir)
10701071
result = Result(output=None, runtime=None, errored=False)
10711072
self.hooks.pre_run_task(self)
1072-
self.audit.start_audit(odir=self.output_dir)
1073+
self.audit.start_audit(odir=output_dir)
10731074
try:
10741075
self.audit.monitor()
10751076
await self._run_task(submitter, rerun=rerun)
10761077
result.output = self._collect_outputs()
10771078
except Exception:
10781079
etype, eval, etr = sys.exc_info()
10791080
traceback = format_exception(etype, eval, etr)
1080-
record_error(self.output_dir, error=traceback)
1081+
record_error(output_dir, error=traceback)
10811082
result.errored = True
10821083
self._errored = True
10831084
raise
10841085
finally:
10851086
self.hooks.post_run_task(self, result)
10861087
self.audit.finalize_audit(result=result)
1087-
save(orig_outdir, result=result, task=self)
1088+
save(output_dir, result=result, task=self)
10881089
# removing the additional file with the chcksum
10891090
(self.cache_dir / f"{self.uid}_info.json").unlink()
10901091
os.chdir(cwd)

0 commit comments

Comments
 (0)