Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ...utils.filemanip import (md5, FileNotFoundError, ensure_list,
simplify_list, copyfiles, fnames_presuffix,
loadpkl, split_filename, load_json, makedirs,
emptydirs, savepkl, to_str, indirectory)
emptydirs, savepkl, to_str, indirectory, silentrm)

from ...interfaces.base import (traits, InputMultiPath, CommandLine, Undefined,
DynamicTraitedSpec, Bunch, InterfaceResult,
Expand Down Expand Up @@ -440,7 +440,6 @@ def run(self, updatehash=False):
for outdatedhash in glob(op.join(self.output_dir(), '_0x*.json')):
os.remove(outdatedhash)


# Hashfile while running
hashfile_unfinished = op.join(
outdir, '_0x%s_unfinished.json' % self._hashvalue)
Expand Down Expand Up @@ -474,7 +473,11 @@ def run(self, updatehash=False):
except Exception:
logger.warning('[Node] Error on "%s" (%s)', self.fullname, outdir)
# Tear-up after error
os.remove(hashfile_unfinished)
if not silentrm(hashfile_unfinished):
logger.warning("""\
Interface finished unexpectedly and the corresponding unfinished hashfile %s \
does not exist. Another nipype instance may be running against the same work \
directory. Please ensure no other concurrent workflows are racing""", hashfile_unfinished)
raise

# Tear-up after success
Expand Down
21 changes: 21 additions & 0 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,27 @@ def emptydirs(path, noexist_ok=False):
makedirs(path)


def silentrm(filename):
"""
Equivalent to ``rm -f``, returns ``False`` if the file did not
exist.

Parameters
----------

filename : str
file to be deleted

"""
try:
os.remove(filename)
except OSError as e:
if e.errno != errno.ENOENT:
raise
return False
return True


def which(cmd, env=None, pathext=None):
"""
Return the path to an executable which would be run if the given
Expand Down