-
Notifications
You must be signed in to change notification settings - Fork 769
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
Cannot except PanicException
in python
#2880
Comments
Due to ABI issues/static linkage, every PyO3-based extension has its own module.add("PanicException", <pyo3::panic::PanicException as pyo3::PyTypeInfo>::type_object(py))?; on a suitable |
This is also true for PanicException - you shouldn't catch it, you should fix the bugs in your code. |
As an aside, please try to be specific here. At the moment, we all know what we are talking about. But the issue might be read by other people in the future where "latest" does not apply any more. |
@adamreichold Thank you! So it is possible to catch all such PanicExceptions in different modules?
I see. Indeed I am using it for some machine learning data generation, and bugs are acceptable as long as it is not frequent - I just throw away that part of data and restart randomly.
changed :) |
I don't think so. As each Python extension built using PyO3 has a different One workaround that might work is to catch except BaseException as e:
if not "PanicException" in str(type(e)):
raise |
Thank you! |
As this is now resolved and there's no intention to change PyO3's design here, I'm going to close this issue. Thanks both! |
Bug Description
Hi thanks for the helpful crate! I need to catch rust panics in python. Example code:
However it does not work, error log:
Yes I can change it to BaseException but that will capture a lot of other exceptions which I should not catch.
I have tried to
import pyo3_runtime
but seems that package does not exist at all.Steps to Reproduce
see above
Backtrace
No response
Your operating system and version
macos
Your Python version (
python --version
)3.9
Your Rust version (
rustc --version
)1.66.1
Your PyO3 version
0.17.3
How did you install python? Did you use a virtualenv?
pip
Additional Info
No response
The text was updated successfully, but these errors were encountered: