[Python-Dev] Debugging opportunity :-)

Tim Peters tim.peters at gmail.com
Fri Apr 14 21:49:35 CEST 2006

When "possible finalizers" were added to generators, the
implementation at first said that all generators need finalizing.  As
a result, some old tests in test_generators.py started leaking cyclic
trash.  As a result of that, someone(s) added a number of explicit
"close" gimmicks to those tests, to break the cycles and stop the

Recently smarter gc code was added, so that most old generators should
no longer say they need finalization.  But the new close-it cruft
added to test_generators wasn't removed, so I thought I'd try that. 
Alas, they still leaked without the close-it cruft.  That eventually
pointed to an off-by-one error in the new PyGen_NeedsFinalizing(),
where reading up trash made it very likely that old generators
containing an active loop would falsely claim they need finalization. 
Alas, fix that, and Python segfaults when running test_generators.

I'm out of time for this now, so wrote up what I know, and attached a
patch sufficient to reproduce it:


It's nominally assigned to Phillip, but for anyone who enjoys a
significant debugging challenge, it's likely to be much more fun than
skinning the Easter Bunny :-)

More information about the Python-Dev mailing list