Giter VIP home page Giter VIP logo

Comments (3)

fundead avatar fundead commented on July 18, 2024

The reason for this is to prevent a circular reference which the GC cannot handle efficiently. Please see this issue for more details: #26 (and the official documentation of this behavior in the warning at https://docs.python.org/2/library/sys.html#sys.exc_info).

I'll add a code comment for those lines in the next release as it does look odd if the reader is unfamiliar with that behavior (it is rather counter-intuitive).

from raygun4py.

donspaulding avatar donspaulding commented on July 18, 2024

I think I understand what the code is trying to accomplish, but I still think it's broken. As I understand the docs you linked to, the recommended pattern for avoiding the circular reference is more something like this:

def some_exception_handler():
    exc_type, exc_val, exc_tb = sys.exc_info()
    try:
        do_stuff_with_exc_info(exc_type, exc_val, exc_tb)
    finally:
        del exc_type, exc_val, exc_tb

The biggest distinction of note is that deling the references to the exc_info() values is not what needs to be guarded by the try clause, it's the cleanup action that needs to take place should anything you are doing with the exc_info values in the try clause throw any kind of exception.

del some_var doesn't throw exceptions when the name some_var is in scope, which it plainly is with just a quick glance at the code, so you don't need to wrap that in a try clause. As it sits now, the only way your except clause will be triggered is via some bug in the python interpreter. Not a very likely scenario.

Also, even if you were concerned about del exc_type, exc_value, exc_traceback somehow failing in the try clause, the following two pieces of code are equivalent in python:

try:
    do_something()
except Exception:
    raise

and

do_something()

In other words, if you have nothing but raise in your except clause, you might as well not wrap the try clause at all, because you're throwing the error up to your caller regardless.

from raygun4py.

fundead avatar fundead commented on July 18, 2024

Hi Don,

I'm inclined to agree with the analysis above, had a quick attempt during the last release at reproducing the actual behavior which didn't work. In order to confirm the impact of this change it looks like I'll need to create a proper repro and profile the GC to see the circular reference. This will allow us to verify removing the raise/altering the logic. As the code is running in production with no (reported) issues as this time we have a policy on not making breaking changes without evidence, so I'll be revisiting this issue and hopefully fixing the logic once I have time to create the repro.

from raygun4py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.