A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-July/027051.html below:

[Python-Dev] patch: try/finally in generators

[Python-Dev] patch: try/finally in generators [Python-Dev] patch: try/finally in generatorsNeil Schemenauer nas@python.ca
Mon, 29 Jul 2002 13:41:12 -0700
I wrote:
> The proposed patch is not correct since it doesn't handle "finally"
> code that creates a new reference to the generator.

It looks like that's not actually a problem since you can't get a hold
of a reference to the generator.  However, here's another bit of
nastiness:

    $ cat > bad.py
    import sys
    import gc

    def g():
        global gen
        self = gen
        try:
            yield 1
        finally:
            gen = self
            
    gen = g()
    gen.next()
    del gen
    gc.collect()
    print gen
    $ ./python bad.py
    Segmentation fault (core dumped)

Basically, the GC has to be taught that generators can have finalizers
and it may not be safe to collect them.  If we allow try/finally in
generators then they can cause uncollectible garbage.  It's not a show
stopper but something else to take into consideration.

  Neil



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4