Peter Otten

Discussion in 'Python' started by Ami Tavory, Feb 14, 2013.

  1. Ami Tavory

    Ami Tavory Guest

    From: Peter Otten <>
    To:
    Cc:
    Date: Thu, 14 Feb 2013 09:00:58 +0100
    Subject: Re: "Exception ... in <generator object ...> ignored" Messages
    Ami Tavory wrote:

    > Hi,
    >
    > Running the unit tests for some generator code, prints, as a side
    > effect,
    > numerous messages of the form:
    >
    > ...
    > Exception NameError: "global name 'l' is not defined" in <generator object
    > _dagpype_internal_fn_act at 0x9d4c500> ignored
    > Exception AttributeError: "'NoneType' object has no attribute 'close'" in
    > <generator object split at 0x7601640> ignored
    > Exception AttributeError: "'NoneType' object has no attribute 'close'" in
    > <generator object split at 0x7601690> ignored
    > ...
    >
    > The tests otherwise run fine.
    >
    > Is there any way to catch the point where such a message originates, and
    > print a traceback? I find it difficult to debug otherwise. I've tried
    > running Python with -W error, catching warnings with context managers, and
    > so forth, but without any success.


    >>> def g():

    .... try:
    .... yield 42
    .... finally:
    .... 1/0
    ....
    >>> for item in g():

    .... break
    ....
    Exception ZeroDivisionError: 'integer division or modulo by zero' in
    <generator object g at 0x7f990243b0f0> ignored

    Can you exhaust the generator?

    >>> for item in g():

    .... pass
    ....
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<stdin>", line 5, in g
    ZeroDivisionError: integer division or modulo by zero

    Explicitly closing the generator seems to work, too:

    >>> x = g()
    >>> next(x)

    42
    >>> x.close()

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<stdin>", line 5, in g
    ZeroDivisionError: integer division or modulo by zero

    -------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------

    Hi Peter,

    Thanks for your answer!

    So basically the thing is that, as you've shown, if you exhaust a
    generator or force-close it, an exception is indeed thrown. However, in
    this were the case then unittest would identify it as a problem, and I
    could relatively easily get a traceback and see from where it's
    originating. However, the unittests are passing fine (except for the pesky
    messages), so it's something else.
    I'm starting to think that what's happening is something like this: I
    have a cascade of generator objects (some hold on to others), and the
    unittests check both the exhaustion case and the non-exhaustion case (both
    cases are valid use cases). *Later on*, after the tests finish, the garbage
    collector starts tearing down the generator cascade, but in a different
    order. Some generators, while closing down, are attempting to close down
    other generators that no longer exist.
    So, notwithstanding your correct answer - I'm still stumped about finding
    out how to get rid of these annoying messages.

    Thanks,

    Ami
    Ami Tavory, Feb 14, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davisro
    Replies:
    3
    Views:
    382
    bruce barker
    Apr 29, 2004
  2. Davisro
    Replies:
    1
    Views:
    368
    George Ter-Saakov
    May 3, 2004
  3. Roedy Green

    Peter van der Linden

    Roedy Green, May 7, 2004, in forum: Java
    Replies:
    7
    Views:
    516
    marcus
    May 10, 2004
  4. Ken North
    Replies:
    0
    Views:
    454
    Ken North
    Mar 1, 2004
  5. saywhat

    Hats off to Peter Bromberg

    saywhat, Jun 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    281
    saywhat
    Jun 4, 2006
Loading...

Share This Page