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


Groups > comp.lang.python > #38881

Peter Otten

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <atavory@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'warnings': 0.03; 'explicitly': 0.04; 'messages.': 0.04; '(except': 0.05; 'attribute': 0.05; 'context': 0.05; 'debug': 0.05; 'finally:': 0.05; 'ignored': 0.05; 'try:': 0.07; 'unittest': 0.07; 'python': 0.09; 'exist.': 0.09; 'garbage': 0.09; 'generators': 0.09; 'modulo': 0.09; 'nameerror:': 0.09; 'def': 0.10; 'cases': 0.15; 'passing': 0.15; '"exception': 0.16; 'effect,': 0.16; 'fine.': 0.16; 'ignored"': 0.16; 'unittests': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'integer': 0.17; 'thu,': 0.17; 'yield': 0.17; 'thanks,': 0.18; 'tests': 0.18; '>>>': 0.18; 'code,': 0.18; 'feb': 0.19; '"",': 0.22; '&gt;&gt;&gt;': 0.22; 'form:': 0.22; 'skip:_ 20': 0.22; 'work,': 0.22; '&gt;': 0.23; 'split': 0.23; 'this:': 0.23; "i've": 0.23; 'seems': 0.23; 'pass': 0.25; 'tried': 0.25; '(most': 0.27; 'order.': 0.27; '+0100': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'received:209.85.212': 0.28; 'fine': 0.28; 'run': 0.28; 'attempting': 0.29; 'catching': 0.29; 'division': 0.29; 'skip:- 90': 0.29; 'date:': 0.29; 'objects': 0.29; 'starts': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'point': 0.31; 'file': 0.32; 'running': 0.32; 'could': 0.32; 'print': 0.32; 'rid': 0.33; 'traceback': 0.33; 'zero': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'skip:& 20': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'otherwise.': 0.35; 'problem,': 0.35; 'so,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'subject:': 0.36; 'but': 0.36; 'closing': 0.36; 'success.': 0.36; 'email addr:python.org': 0.36; 'item': 0.37; 'skip:z 10': 0.37; 'received:209': 0.37; 'unit': 0.38; 'from:': 0.38; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'where': 0.40; 'think': 0.40; 'your': 0.60; "you've": 0.61; 'identify': 0.61; 'side': 0.61; 'email name:python-list': 0.62; 'relatively': 0.62; 'close': 0.63; 'different': 0.63; 'skip:n 10': 0.63; 'else.': 0.65; '2013': 0.84; 'otten': 0.84; 'peter,': 0.84; 'numerous': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=gu+ficw3VCxVjnrKrS4hq1meKgwsqDHNKMqYICLkLok=; b=qYhmCCHHLqD+F1QADcd0GzBMHHtiBZji4WwIW10RLxh17gmc2KYVSjXgzpjC9SeuH4 DsfeKNx3VdPnNjIQobJW9koxIXHxsOFBQu3ypTYiIRbbPtsgWoJt7jmdORh0ymQzqciF o3xpab80buAaEHPNzPqHI+XcOiYFJSLKkHpXC5MCy9WEgvTLIJ3rzcu/GI9qkFQLXgbP G9htUXrcwFB3uH17A9WjWNH342pKaLXpLpCX0BBS2+DvkfsrVTF6s5lHsjtH+H1gJ+9U NGz7+F5wXOlOt67mG1Poa/M12d1dHar/caZZeVNh2/oq5AmtV7+Em7u14qauzOkecgc+ wYxQ==
MIME-Version 1.0
X-Received by 10.52.66.41 with SMTP id c9mr30939763vdt.32.1360870925778; Thu, 14 Feb 2013 11:42:05 -0800 (PST)
Date Thu, 14 Feb 2013 21:42:05 +0200
Subject Peter Otten
From Ami Tavory <atavory@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=20cf3071ca9c1dc01f04d5b474d9
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1783.1360870934.2939.python-list@python.org> (permalink)
Lines 189
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360870934 news.xs4all.nl 6920 [2001:888:2000:d::a6]:53702
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38881

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

From: Peter Otten <__peter__@web.de>
To: python-list@python.org
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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Peter Otten Ami Tavory <atavory@gmail.com> - 2013-02-14 21:42 +0200

csiph-web