kmonsoor / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

pyglet.image.load does not close file #670

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
run python3  -Wdefault  test_pyglet_error.py

Paste in the traceback or error message:
The following warning is printed:
test_pyglet_error.py:3: ResourceWarning: unclosed file <_io.BufferedReader 
name='preview.png'>
  a = pyglet.image.load("preview.png")

pyglet: revision 2779:7d0ddfa8f7d0(Sep 21 11:43:21 2013)
python  3.2.3

The reason for the problem is that pyglet.image.load does not close the file 
but instead wait for the GC to fix it. This is considered bad practice and is 
the reason for the warning printed with -Wdefault. -Wdefault is active as 
standard when running the unittest module causing a lot of warning messages 
when running unittests.

Patch is included and have been verified on python 2.7.3 and 3.2.3

Original issue reported on code.google.com by norberg....@gmail.com on 28 Sep 2013 at 9:21

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by useboxnet on 28 Sep 2013 at 11:06

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 304c4b1dc7f1.

Original comment by useboxnet on 29 Sep 2013 at 9:00

GoogleCodeExporter commented 9 years ago
Thanks for the report and the patch.

I've used a different approach (less code, close also on exceptions), but the 
result should be the same.

Original comment by useboxnet on 29 Sep 2013 at 9:02