Handle Python layer exceptions correctly #2462
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(This is a simplified alternative implementation of part of the first commit of #2001, plus a test.)
As noted by @tnarihi, Python layer exceptions are not handled correctly in pycaffe.
PyErr_Print
is used to display exception text on stderr, but this has the side effect of clearing the exception, which results in an additionalSystemError: NULL return without exception set
.The exceptions get passed through correctly if we simply don't try to catch and print them; that's the first commit. (Note that the Python interpreter will print these exceptions, if uncaught; it's only the
caffe
tool that won't.) Since we'd still like to see the exception text when using thecaffe
tool, the second commit adds a single,ifdef
ed,catch
/PyErr_Print
block to the tool code. (There's no harm in callingPyErr_Print
since we know we're not in the interpreter.)I prefer this approach to the one in #2001, for these reasons:
The disadvantage of this approach is that:
caffe
toolLet me know what you think @tnarihi and others, and thanks @tnarihi for pointing out this issue. (Note also that this does not include all of the exception-fixing functionality from #2001, which I'll plan to check out separately.)