Skip to content

Commit afa74b7

Browse files
committed
make sure the OSError when cwd is deleted by other process is handled gracefully
1 parent 371a10b commit afa74b7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

nipype/pipeline/engine/nodes.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ def run(self, updatehash=False):
428428
savepkl(op.join(outdir, '_inputs.pklz'),
429429
self.inputs.get_traitsfree())
430430

431-
cwd = os.getcwd()
431+
try:
432+
cwd = os.getcwd()
433+
except OSError:
434+
# Changing back to cwd is probably not necessary
435+
# but this makes sure there's somewhere to change to.
436+
cwd = os.path.split(outdir)[0]
437+
logger.debug('Current folder does not exist, changing to "%s" instead.', cwd)
438+
432439
os.chdir(outdir)
433440
try:
434441
result = self._run_interface(execute=True)
@@ -1009,8 +1016,8 @@ def inputs(self):
10091016

10101017
@property
10111018
def outputs(self):
1012-
if self._interface._outputs():
1013-
return Bunch(self._interface._outputs().get())
1019+
if self.interface._outputs():
1020+
return Bunch(self.interface._outputs().get())
10141021

10151022
def _make_nodes(self, cwd=None):
10161023
if cwd is None:
@@ -1030,7 +1037,7 @@ def _make_nodes(self, cwd=None):
10301037
base_dir=op.join(cwd, 'mapflow'),
10311038
name=nodename)
10321039
node.plugin_args = self.plugin_args
1033-
node._interface.inputs.trait_set(
1040+
node.interface.inputs.trait_set(
10341041
**deepcopy(self._interface.inputs.get()))
10351042
node.interface.resource_monitor = self._interface.resource_monitor
10361043
for field in self.iterfield:
@@ -1177,6 +1184,7 @@ def _run_interface(self, execute=True, updatehash=False):
11771184
if path.split(op.sep)[-1] not in nodenames:
11781185
dirs2remove.append(path)
11791186
for path in dirs2remove:
1187+
logger.debug('[MapNode] Removing folder "%s".' , path)
11801188
shutil.rmtree(path)
11811189

11821190
return result

nipype/pipeline/plugins/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def _remove_node_dirs(self):
408408
continue
409409
if self.proc_done[idx] and (not self.proc_pending[idx]):
410410
self.refidx[idx, idx] = -1
411-
outdir = self.procs[idx]._output_directory()
411+
outdir = self.procs[idx].output_dir()
412412
logger.info(('[node dependencies finished] '
413413
'removing node: %s from directory %s') %
414414
(self.procs[idx]._id, outdir))

0 commit comments

Comments
 (0)