Skip to content

Strange return values in nodes.py #1446

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

Closed
alexsavio opened this issue Apr 20, 2016 · 6 comments
Closed

Strange return values in nodes.py #1446

alexsavio opened this issue Apr 20, 2016 · 6 comments

Comments

@alexsavio
Copy link
Contributor

alexsavio commented Apr 20, 2016

Hi,

Today I ran into an error on the master branch and went to check the code.

I saw that the yield variables in:
https://github.com/nipy/nipype/blob/master/nipype/pipeline/engine/nodes.py#L1154
don't make sense.
The thing is that err will be None always, if the exception is raised and then err has a value the function will raise that exception instead of yield-ing the values.

I am putting this issue here because I don't know what is the objective of this function. I guess that the code inside the exception needs an 'else: pass' and maybe a finally statement.

@alexsavio
Copy link
Contributor Author

alexsavio commented Apr 20, 2016

I have checked this with a colleague and maybe it is because I am using Python 3.5 and this is not being tested.
This does work on Python 2.7 though.

The exception raised when I run it is:

base.py report_crash: INFO Traceback (most recent call last):
  File "/home/alexandre/Software/nipype/nipype/pipeline/plugins/multiproc.py", line 19, in run_node
    result['result'] = node.run(updatehash=updatehash)
  File "/home/alexandre/Software/nipype/nipype/pipeline/engine/nodes.py", line 392, in run
    self._run_interface()
  File "/home/alexandre/Software/nipype/nipype/pipeline/engine/nodes.py", line 1301, in _run_interface
    updatehash=updatehash))
  File "/home/alexandre/Software/nipype/nipype/pipeline/engine/nodes.py", line 1164, in _collate_results
    for i, node, err in nodes:
  File "/home/alexandre/Software/nipype/nipype/pipeline/engine/nodes.py", line 1157, in _node_runner
    yield i, node, err
UnboundLocalError: local variable 'err' referenced before assignment

My impression is that the err variable is being deleted after the except statement (which is strange). So I made the following and now I see that the underlying error comes from Matlab.

    def _node_runner(self, nodes, updatehash=False):
        for i, node in nodes:
            err = None
            try:
                node.run(updatehash=updatehash)
            except Exception as exc:
                if str2bool(self.config['execution']['stop_on_first_crash']):
                    self._result = node.result
                    raise
                else:
                    err = exc
            finally:
                yield i, node, err

@alexsavio
Copy link
Contributor Author

alexsavio commented Apr 20, 2016

Anyway, IMO this small modification in the _node_runner function makes it a bit easier to read. However the re-assignement err = exc is not needed for the finally block.

@alexsavio
Copy link
Contributor Author

I have found an explanation on the matter here:
http://stackoverflow.com/questions/35545299/tracebacks-in-python-3-5

@alexsavio
Copy link
Contributor Author

I've made a PR #1447 to fix this.

@ashgillman
Copy link
Contributor

I am still getting this error, on Python 3.4.4, Nipype 12.0. I have had a look through the Python 3.5 release changes but I can't find reference to anything that would still cause this.

@ashgillman
Copy link
Contributor

@alexsavio Your previous comment seems to fix. I threw into PR #1551

satra added a commit to satra/nipype that referenced this issue Dec 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants