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
Interpreter aborts when chaining an infinite number of exceptions #50278
Comments
def error_handle():
try:
print(5/0)
except:
error_handle()
error_handle() Fatal Python error: Cannot recover from stack overflow. The interpreter should not crash. Perhaps a RuntimeError should be |
This is normal behaviour, actually. The RuntimeError *is* raised, but |
Hmm, the interpreter should not crash so easily with pyre Python code. The exact behavior seem to depend on where the recursion limit is detected:
Here is a tentative patch. |
Amaury, your patch might make some individual cases better, but it won't Also, it makes things worse in the following case: def recurse():
try:
recurse()
except:
recurse()
recurse() (the script goes into an uninterruptible infinite loop, rather than More useful, IMHO, would be to patch Py_FatalError() so that a traceback |
The code you posted causes an infinite loop in the 2.x branch as well. |
I do not see what the "desired result" is in your example. The code is Also, this is not an actual crash (as in "segmentation fault"). It is The fact that some errors cannot be recovered from is an unavoidable |
I knew that python handles infinite recursion and gracefully errors out, The code is in no way trying to circumvent anything. If there is about I am sorry I simply do not see your point. This seems so obvious. There I am not terribly thrilled about your attitude of "we might as well |
While we seem to disagree on whether this a real bug (and I'll leave it (for various ways of producing fatal errors, please search for |
|
Well, perhaps something like bpo-1195571 should be added. |
I believe bpo-3555, bpo-7338, and *13644 are basically duplicates of this issue. I have left this one open because it has a try at a patch. I think any patch should be tested with the other examples. I agree with Antoine that an intentional exit is not a crash. Now, if someone can find a way to better handle infinite recursion mixed with exceptions, without re-introducing real crashes or eliminating the benefits of the 3.0 changes, great. Yury, I think Antoine's point is that gracefully handling all the different kinds of programming mistakes in a finite system is a delicate and difficult balancing act. |
Rather than aborting with a stack overflow, I feel it is more natural to raise an exception. If it is not too difficult to implement, perhaps another type of exception should be raised. Since chained exceptions are new to 3.x, there should be a new exception to describe errors that happen in chaining. Perhaps stopping chaining at a certain depth and truncating all further exceptions with a blanket "ChainingException" exception. Or perhaps truncating the chain and wrapping it in another exception before returning it to user code. While this is my proposed solution, I apologize I cannot volunteer to write the patch. The time investment on my part would involve learning most of the working of the interpreter. Perhaps someone who is already familiar with it would be interested. |
FWIW, I concur with Antoine on this one. |
Closing as won't fix. There is no sane way around the current behaviour. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: