<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 18, 2017 at 2:48 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, 18 Sep 2017 11:31:12 +0200<br>
Victor Stinner <<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>> wrote:<br>
><br>
> Ideally, CPython 3.x should never create reference cycles. Removing<br>
> Exception.__traceback__ is the obvious "fix" for the issue. But I<br>
> expect that slowly, a lot of code started to rely on the attribute,<br>
> maybe even for good reasons :-)<br>
<br>
</span>The real issue is not reference cycles, but the fact that a traceback<br>
frame keeps all locals alive.  When the frame's execution is finished,<br>
that information is practically almost always useless, but is kept for<br>
the rare cases of debugging (and perhaps dubious features such as<br>
some of py.test's magic).  So we're constantly paying the price of this<br>
minor, albeit probably useful (*), debugging-related feature with<br>
annoying object lifetime issues that are sometimes quite difficult to<br>
track down and solve.<br>
<br>
(*) (I've hardly ever used pdb so I don't know if people often examine<br>
the locals of finished frames, but I suppose some do)<br></blockquote><div><br></div><div>Yes, that's what `<a href="http://pdb.pm">pdb.pm</a>()` is for.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Perhaps it would be useful to have a way to tell the interpreter to<br>
automatically clear all locals on frames when they have finished<br>
executing.  It could be a thread-local setting (or, better, a PEP 550<br>
context variable setting).<br></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">In Python 2 the traceback was not part of the exception object because there was (originally) no cycle GC. In Python GC we changed the awkward interface to something more useful, because we could depend on GC. Why are we now trying to roll back this feature? We should just improve GC. (Or perhaps you shouldn't be raising so many exceptions. :-)<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>