Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-07 Thread Victor Stinner
2014-03-07 6:25 GMT+01:00 Nick Coghlan : >> Uh, really? If you want to suppress all reference cycles, you *have* to >> remove __traceback__. >> >> The problem is to make computation of the traceback summary lightweight >> enough that it doesn't degrade performance in the common case where you >> do

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Nick Coghlan
On 6 Mar 2014 23:44, "Antoine Pitrou" wrote: > > Le 05/03/2014 23:53, Nick Coghlan a écrit : >> >> >> __traceback__ wouldn't change [...] > > > Uh, really? If you want to suppress all reference cycles, you *have* to remove __traceback__. > > The problem is to make computation of the traceback summ

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Victor Stinner
Hi, 2014-03-06 16:19 GMT+01:00 Victor Stinner : > By the way, here is my test script to try to create a lightweight > traceback object without references to locals: > https://bitbucket.org/haypo/misc/src/tip/python/suppress_locals.py > > It works if there is no chained exception. I updated my pro

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Greg Ewing
Antoine Pitrou wrote: We might allow the creation of traceback objects, but without any custom frame objects it is unclear how useful that would be. When I was implementing Pyrex, I would have found it very useful to be able to create Traceback objects without Frames, but only if the Traceback

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Guido van Rossum
It's all very old C code that's deeply intertwined with interpreter internals. Who knows what kind of assumptions are made by some of the C code consuming frames and tracebacks... On Thu, Mar 6, 2014 at 12:38 PM, Xavier Morel wrote: > On 2014-03-06, at 19:32 , Guido van Rossum wrote: > > But in

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Xavier Morel
On 2014-03-06, at 19:32 , Guido van Rossum wrote: > But inspect is in the stdlib. Surely changing inspect.py is less > controversial than amending the semantics of frame objects. I've no idea, I'm just giving a case where I could have used the ability to create traceback objects even without the

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Yury Selivanov
But having exceptions without '__traceback__' affects not only the inspect module, but also lots of other code. It will make harder to write generic error reporting code, as you'd need to check for __traceback__ first, and then, if it's None, look for some other, asyncio specific attribute. I th

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Guido van Rossum
But inspect is in the stdlib. Surely changing inspect.py is less controversial than amending the semantics of frame objects. On Thu, Mar 6, 2014 at 10:10 AM, Xavier Morel wrote: > On 2014-03-06, at 16:52 , Antoine Pitrou wrote: > > Le 06/03/2014 16:03, Yury Selivanov a écrit : > >> > >> On 2014

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Xavier Morel
On 2014-03-06, at 16:52 , Antoine Pitrou wrote: > Le 06/03/2014 16:03, Yury Selivanov a écrit : >> >> On 2014-03-06, 8:42 AM, Antoine Pitrou wrote: >>> Le 05/03/2014 23:53, Nick Coghlan a écrit : __traceback__ wouldn't change [...] >>> >>> Uh, really? If you want to suppress all refer

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Antoine Pitrou
Le 06/03/2014 16:03, Yury Selivanov a écrit : On 2014-03-06, 8:42 AM, Antoine Pitrou wrote: Le 05/03/2014 23:53, Nick Coghlan a écrit : __traceback__ wouldn't change [...] Uh, really? If you want to suppress all reference cycles, you *have* to remove __traceback__. The problem is to make c

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Victor Stinner
2014-03-06 14:42 GMT+01:00 Antoine Pitrou : > Le 05/03/2014 23:53, Nick Coghlan a écrit : >> >> >> __traceback__ wouldn't change [...] > > > Uh, really? If you want to suppress all reference cycles, you *have* to > remove __traceback__. > > The problem is to make computation of the traceback summar

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Yury Selivanov
On 2014-03-06, 8:42 AM, Antoine Pitrou wrote: Le 05/03/2014 23:53, Nick Coghlan a écrit : __traceback__ wouldn't change [...] Uh, really? If you want to suppress all reference cycles, you *have* to remove __traceback__. The problem is to make computation of the traceback summary lightwei

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-06 Thread Antoine Pitrou
Le 05/03/2014 23:53, Nick Coghlan a écrit : __traceback__ wouldn't change [...] Uh, really? If you want to suppress all reference cycles, you *have* to remove __traceback__. The problem is to make computation of the traceback summary lightweight enough that it doesn't degrade performance i

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Nick Coghlan
On 6 Mar 2014 08:32, "Yury Selivanov" wrote: > > > On 2014-03-05, 4:54 PM, Nick Coghlan wrote: >> >> On 6 Mar 2014 02:43, "Antoine Pitrou" wrote: >>> >>> Le 05/03/2014 17:37, Victor Stinner a écrit : >>> Python 3.4 introduced frame.clear(), but frame.clear() raises an RuntimeError if th

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Yury Selivanov
On 2014-03-05, 4:54 PM, Nick Coghlan wrote: On 6 Mar 2014 02:43, "Antoine Pitrou" wrote: Le 05/03/2014 17:37, Victor Stinner a écrit : Python 3.4 introduced frame.clear(), but frame.clear() raises an RuntimeError if the frame is still running. And it doesn't break all reference cycles. An o

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Eric Snow
On Wed, Mar 5, 2014 at 2:54 PM, Nick Coghlan wrote: > Guido had a fix in mind - splitting traceback formatting into two pieces. > The first would convert a traceback to a sequence of named tuples, the > second would do the actual string formatting. +1 This is basically how I've handled pickling

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Guido van Rossum
I think it was http://bugs.python.org/issue17911 On Wed, Mar 5, 2014 at 1:54 PM, Nick Coghlan wrote: > > On 6 Mar 2014 02:43, "Antoine Pitrou" wrote: > > > > Le 05/03/2014 17:37, Victor Stinner a écrit : > > > >> > >> Python 3.4 introduced frame.clear(), but frame.clear() raises an > >> Runtim

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Nick Coghlan
On 6 Mar 2014 02:43, "Antoine Pitrou" wrote: > > Le 05/03/2014 17:37, Victor Stinner a écrit : > >> >> Python 3.4 introduced frame.clear(), but frame.clear() raises an >> RuntimeError if the frame is still running. And it doesn't break all >> reference cycles. >> >> An obvious workaround is to sto

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Yury Selivanov
On 2014-03-05, 11:37 AM, Victor Stinner wrote: [snip] I tried to write "views" of the traceback (and frames), but Exception.__traceback__ rejects types other than traceback and traceback instances cannot be created. It's possible to store the traceback somewhere else and set Exception.__traceba

Re: [Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Antoine Pitrou
Le 05/03/2014 17:37, Victor Stinner a écrit : Python 3.4 introduced frame.clear(), but frame.clear() raises an RuntimeError if the frame is still running. And it doesn't break all reference cycles. An obvious workaround is to store the traceback as text, but this operation is "expensive" especi

[Python-Dev] Reference cycles in Exception.__traceback__

2014-03-05 Thread Victor Stinner
Hi, Python 3 now stores the traceback object in Exception.__traceback__ and exceptions can be chained through Exception.__context__. It's convinient but it introduced tricky reference cycles if the exception object is used out of the except block. Refrences: Exception.__traceback__ -> traceback -