[Python-bugs-list] Bug with Threaded exceptions? (PR#151)
jam@camros.com
jam@camros.com
Tue, 7 Dec 1999 01:12:16 -0500 (EST)
I Agree that the ctor/dtor is a C++ idiom, we'll re-arange our code
to "acquire"/"release" locks instead of trying to do things using
an object's ctor/dtor (which as you stated are not reliable when
using a non-ref counted vm like JPython).
thanks,
-jeff
>
> Python defines neither the lifetime of objects nor makes any guarantee about
> which threads will run finalizers. Just facts of life! Acquiring/releasing
> a lock in an object ctor/dtor is a C++ idiom that doesn't carry over (C++
> doesn't say anything about threads either, but does define the lifetime of
> local vrbls). It *usually* works OK in CPython, but usually doesn't in
> JPython.
>
> In your particular case, the local vrbl "a" is still alive after function
> exit because it's still reachable via the traceback object created by the
> exception. Among other things, the traceback object contains the chain of
> stack frames (which in turn contain the local vrbls) active at the time the
> exception was triggered. Binding sys.exc_traceback to, e.g., None will
> usually make it unreachable again (and so trigger CPython's refcount-based
> garbage collection of "a").
>
> I don't know of any way around this except using by try/finally in one way
> or another. In any case, it's not a bug -- it's functioning as designed.
>
>