Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: load_resultfile crashes if open resultsfile from crashed job #3182

Merged
merged 13 commits into from
Mar 9, 2020
Merged
2 changes: 1 addition & 1 deletion nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def load_resultfile(results_file, resolve=True):
raise FileNotFoundError(results_file)

result = loadpkl(results_file)
if resolve and result.outputs:
if resolve and getattr(result, "outputs", None):
try:
outputs = result.outputs.get()
except TypeError: # This is a Bunch
Expand Down
35 changes: 35 additions & 0 deletions nipype/pipeline/plugins/tests/test_sgelike.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from nipype.pipeline.plugins.base import SGELikeBatchManagerBase
from nipype.interfaces.utility import Function
import nipype.pipeline.engine as pe
import pytest
from unittest.mock import patch
import subprocess


def crasher():
raise ValueError()


def submit_batchtask(self, scriptfile, node):
self._pending[1] = node.output_dir()
subprocess.call(["bash", scriptfile])
return 1


def is_pending(self, taskid):
return False


@patch.object(SGELikeBatchManagerBase, "_submit_batchtask", new=submit_batchtask)
@patch.object(SGELikeBatchManagerBase, "_is_pending", new=is_pending)
def test_crashfile_creation(tmp_path):
pipe = pe.Workflow(name="pipe", base_dir=str(tmp_path))
pipe.config["execution"]["crashdump_dir"] = str(tmp_path)
pipe.add_nodes([pe.Node(interface=Function(function=crasher), name="crasher")])
sgelike_plugin = SGELikeBatchManagerBase("")
with pytest.raises(RuntimeError) as e:
assert pipe.run(plugin=sgelike_plugin)
assert str(e.value) == "Workflow did not execute cleanly. Check log for details"

crashfiles = tmp_path.glob("crash*crasher*.pklz")
assert len(list(crashfiles)) == 1