Handle Python layer exceptions correctly#2462
Merged
shelhamer merged 3 commits intoBVLC:masterfrom Aug 6, 2015
Merged
Conversation
Previously, PyErr_Print was used to print Python exceptions. This has the side effect of clearing the exception, which results in (an additional) SystemError in the Python interpreter. Exception printing from the caffe binary tool is re-added in a future commit.
Member
|
Merging as I agree that this is simpler than the solution in #2001. Thanks Jon and thanks Takuya for raising the issue! |
shelhamer
added a commit
that referenced
this pull request
Aug 6, 2015
Handle Python layer exceptions correctly
ctrevino
added a commit
to Robotertechnik/caffe
that referenced
this pull request
Aug 6, 2015
Merge pull request BVLC#2462 from longjon/correct-python-exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_Printis 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
caffetool that won't.) Since we'd still like to see the exception text when using thecaffetool, the second commit adds a single,ifdefed,catch/PyErr_Printblock to the tool code. (There's no harm in callingPyErr_Printsince 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:
caffetoolLet 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.)