Skip to content
Prev Previous commit
Second attempt at fixing nodes.py, moved indirectory to an appropriat…
…e place
  • Loading branch information
achetverikov committed Sep 5, 2018
commit e4894a96efdeb1c0eb00d1ceaba721f672f39733
43 changes: 22 additions & 21 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,29 +559,30 @@ def _load_results(self):
result, aggregate, attribute_error = _load_resultfile(cwd, self.name)
# try aggregating first
if aggregate:
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)
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)
with indirectory(cwd):
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()

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()
return result

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