Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31826 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2012-10-20 17:28 -0600 |
| Last post | 2012-10-20 17:28 -0600 |
| 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.
Re: 'generator ignored GeneratorExit'' Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-20 17:28 -0600
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-10-20 17:28 -0600 |
| Subject | Re: 'generator ignored GeneratorExit'' |
| Message-ID | <mailman.2571.1350775743.27098.python-list@python.org> |
On Sat, Oct 20, 2012 at 2:03 PM, Charles Hixson
<charleshixsn@earthlink.net> wrote:
> If I run the following code in the same module, it works correctly, but if I
> import it I get the message:
> Exception RuntimeError: 'generator ignored GeneratorExit' in <generator
> object getNxtFile at 0x7f932f884f50> ignored
>
> def getNxtFile (startDir, exts = ["txt", "utf8"]):
> try:
> for path in getNxtPath (startDir, exts):
> try:
> fil = open (path, encoding = "utf-8-sig")
> yield fil
> except:
> print ("Could not read: ", path)
> except GeneratorExit:
> raise StopIteration
>
> The message appears to be purely informational, but I *would* like to fix
> whatever problem it's reporting, and none of the changes that I've tried
> have worked. What *should* I be doing?
The bare except is probably catching the GeneratorExit exception and
swallowing it. Try catching a more specific exception like OSError or
even just Exception instead.
Also, you don't need to explicitly catch GeneratorExit just to raise
StopIteration. The generator will normally stop on GeneratorExit,
provided the exception is actually able to propagate up.
Back to top | Article view | comp.lang.python
csiph-web