Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38852 > unrolled thread

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

Started byPeter Otten <__peter__@web.de>
First post2013-02-14 09:00 +0100
Last post2013-02-14 09:00 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: "Exception ... in <generator object ...> ignored" Messages Peter Otten <__peter__@web.de> - 2013-02-14 09:00 +0100

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

FromPeter Otten <__peter__@web.de>
Date2013-02-14 09:00 +0100
SubjectRe: "Exception ... in <generator object ...> ignored" Messages
Message-ID<mailman.1760.1360828866.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web