Re: "Exception ... in <generator object ...> ignored" Messages

Discussion in 'Python' started by Peter Otten, Feb 14, 2013.

  1. Peter Otten

    Peter Otten Guest

    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
    Peter Otten, 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. Rukmal Fernando
    Replies:
    4
    Views:
    838
    Richard Grimes [MVP]
    Oct 27, 2003
  2. piyush
    Replies:
    0
    Views:
    1,837
    piyush
    Jul 14, 2004
  3. Robert Rossney
    Replies:
    1
    Views:
    899
    netnews.microsoft.com
    Mar 1, 2005
  4. Ami Tavory
    Replies:
    0
    Views:
    130
    Ami Tavory
    Feb 14, 2013
  5. Peter Otten
    Replies:
    0
    Views:
    153
    Peter Otten
    Feb 15, 2013
Loading...

Share This Page