Garbage collection problem with generators

Haochuan Guo guohaochuan at gmail.com
Wed Dec 28 08:14:45 EST 2016


Sorry about breaking the rule.

I'm just curios about this problem. And I'm using this workaround to prevent
redundant resource creation.

https://gist.githubusercontent.com/wooparadog/16948ca6c8ffb22214bf491a280406da/raw/-


On Wed, Dec 28, 2016 at 9:12 PM Chris Angelico <rosuav at gmail.com> wrote:

> 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
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list