-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Stop including location exception was caught in Failure #12230
Comments
At the time that this code was written, the stack was only present during catching of the exception, and we had to capture it at that moment or it would be lost. Today, the stack is already preserved on the exception itself, as Could we turn This is not necessarily a fully compatible change, but it's certainly more compatible than just dropping the information, and the only place it would be a problem is if the user is mutably re-raising the same exception, and that just isn't a practical concern most of the time in non-Twisted code, so I doubt it would be a problem for us either. |
Probably could do that, yeah. Keep in mind though that That being said, the most expensive thing is |
To make maybe this clearer, options are:
|
Wait, what is |
The purpose is to avoid creating expensive or uncollectable cycles. Perhaps we could tone that down if |
I mean |
Gotcha. I was just a little thrown because you used both, and I thought you were trying to draw a distinction:) |
Update: Wrote some stuff here that was wrong, deleting (didn't realize the traceback's |
After further research, going over the alternatives, only things I can come up with are:
Not viable:
So the question is, can we not wipe In 2002 Python didn't have garbage collection, so circular references would lead to memory leaks. These days, Python does have support for cleaning up circular references. I would therefore suggest that |
Making |
I created #12234 as an alternative proposal to this issue. |
In fairness to your various corrections here I think I might also be a little confused about the purpose of these different variables :) |
How much time / work is |
I already fixed |
After some thought and discussion in #12234, I would like to reiterate the desire in this issue not to include the "where the exception was caught" in the output. Or, to put it another way, the stack trace above where the try/except caught the exception. So far I haven't had any response indicating this information is useful. Maybe it is! But if it isn't, it's a lot of work for no reason. To reiterate the question: Twisted's error output has a traceback going all the way from the top of the stack down to the bottom. Python only reports part of that info, from inside the try/except to the bottom. Is there a reason we can't just stick to what Python does? |
OK, let me address my own view on this specific question: I am happy to just do what Python does. I think that including this additional information is another historical relic, attempting to give developers something to work from when dealing with inscrutable tracebacks that appeared to originate from nowhere due to the relative lack of information that Deferreds had to work with. Nowadays async/await Deferred call stacks are perfectly legible, and this concern is less and less relevant as more sequential code adopts that pattern, which is more efficient than long callback chains anyway. Additionally it's not clear that this information was ever very useful, just an oblique additional clue in confusing circumstances. |
(Not to mention the fact that, as you have already mentioned, Python's native tracebacks look much nicer these days anyway, and we have missed several generations of substantial improvements.) |
FWIW, when I was new to Twisted I had to learn how to read Twisted tracebacks by skipping to the |
OK, let's get rid of it. |
About 2/3rds of the time spent in creating
Failure
objects, and therefore in error handling inDeferred
, is constructingDeferred.stack
. I would argue this isn't necessary, insofar as Python doesn't include this info, and it's a huge performance hit.Comparing Python tracebacks to Failure tracebacks
Consider the following script:
When run:
Notice that Twisted includes where the Failure was created, whereas Python only includes the traceback.
Why omit this? Performance
Two thirds of the time spent in
Deferred
error handling ofFailure
(as measured by the relevant benchmark) is tied in creatingDeferred.stack
.A compromise
If we want to be extra nice, this extra info can be turned on when
Deferred.debug
is turned on.A counterargument
It may be that the info of "where did we catch the exception" is super-helpful. I am not sure I have enough relevant experience in debugging production Twisted applications to have a good opinion.
The text was updated successfully, but these errors were encountered: