Skip to content
45 changes: 23 additions & 22 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,28 +559,29 @@ def _load_results(self):
result, aggregate, attribute_error = _load_resultfile(cwd, self.name)
# try aggregating first
if aggregate:
logger.debug('aggregating results')
if attribute_error:
old_inputs = loadpkl(op.join(cwd, '_inputs.pklz'))
self.inputs.trait_set(**old_inputs)
if not isinstance(self, MapNode):
self._copyfiles_to_wd(linksonly=True)
aggouts = self._interface.aggregate_outputs(
needed_outputs=self.needed_outputs)
runtime = Bunch(
cwd=cwd,
returncode=0,
environ=dict(os.environ),
hostname=socket.gethostname())
result = InterfaceResult(
interface=self._interface.__class__,
runtime=runtime,
inputs=self._interface.inputs.get_traitsfree(),
outputs=aggouts)
_save_resultfile(result, cwd, self.name)
else:
logger.debug('aggregating mapnode results')
result = self._run_interface()
with indirectory(cwd):
logger.debug('aggregating results')
if attribute_error:
old_inputs = loadpkl(op.join(cwd, '_inputs.pklz'))
self.inputs.trait_set(**old_inputs)
if not isinstance(self, MapNode):
self._copyfiles_to_wd(linksonly=True)
aggouts = self._interface.aggregate_outputs(
needed_outputs=self.needed_outputs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, I think we want to try narrowing the "critical section" where we modify the working directory. I think it might actually just be here:

with indirectory(cwd): aggouts = self._interface.aggregate_outputs( needed_outputs=self.needed_outputs)

Almost all other function calls use the cwd directly.

By keeping it narrow, we effectively mark places where we're working-directory dependent, which may be useful in future refactors.

runtime = Bunch(
cwd=cwd,
returncode=0,
environ=dict(os.environ),
hostname=socket.gethostname())
result = InterfaceResult(
interface=self._interface.__class__,
runtime=runtime,
inputs=self._interface.inputs.get_traitsfree(),
outputs=aggouts)
_save_resultfile(result, cwd, self.name)
else:
logger.debug('aggregating mapnode results')
result = self._run_interface()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here's a potential other place we might want to wrap in indirectory(cwd). I would test without, first.

return result

def _run_command(self, execute, copyfiles=True):
Expand Down