Garbage collection problem with generators

Chris Angelico rosuav at gmail.com
Wed Dec 28 08:11:59 EST 2016


On Wed, Dec 28, 2016 at 9:03 PM, Haochuan Guo <guohaochuan at gmail.com> wrote:
> Anyone? The script to reproduce this problem is in:
>
> https://gist.github.com/wooparadog/766f8007d4ef1227f283f1b040f102ef
>
> On Fri, Dec 23, 2016 at 8:39 PM Haochuan Guo <guohaochuan at gmail.com> wrote:
>
>> This is reproducible with python2.7, but not in python3.5. I've also tried
>> with `thread` instead of `gevent`, it still happens. I'm guessing it's
>> related to garbage collection of generators.
>>
>> Did I bump into a python2 bug? Or am I simply wrong about the way to close
>> generators...?

(Please don't top-post.)

Maybe the fix is to just use Python 3.5+? :) It probably is to do with
the garbage collection of generators; so you may want to consider
using something very explicit (eg a context manager) to ensure that
you call gen.close().

ChrisA



More information about the Python-list mailing list