[Python-Dev] Re: Useful thread project for 2.5?

Phillip J. Eby pje at telecommunity.com
Mon Mar 7 03:34:00 CET 2005

At 02:42 PM 3/6/05 -0800, Fazal Majid wrote:
>I suspect integrating this feature (let's call it sys._current_frames() 
>for the sake of argument, although it probably belongs in the threads 
>module) in the core is not going to be quite as trivial as you say, as 
>there are potential memory leaks. If the function returns a dictionary, it 
>should probably be a weak dict to avoid a circular reference between the 
>frame of the thread that calls _current_frames and its locals that contain 
>the returned dictionary.

Given the primary use case as a debugging tool, I don't think the 
circularity will have any significant problems.  It would be simpler to 
just document that a caller should do this:

         framedict = sys._current_frames()
         # do stuff here
         framedict = None  # break the cycle, allowing GC

More information about the Python-Dev mailing list