Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Aug 3, 2013, 6:45 AM

Post #1 of 11 (32 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

New submission from Vajrasky Kok:

This python is compiled with --with-pydebug option.

[sky [at] localhos cpython]$ cat /tmp/a.txt
manly man likes cute cat.
[sky [at] localhos cpython]$ ./python
Python 3.4.0a0 (default:e408e821d6c8, Jul 27 2013, 10:49:54)
[GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from formatter import test
>>> test('/tmp/a.txt')
manly man likes cute cat.
__main__:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/a.txt' mode='r' encoding='UTF-8'>
>>>
[sky [at] localhos cpython]$ ./python Lib/formatter.py /tmp/a.txt
manly man likes cute cat.
Lib/formatter.py:445: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/a.txt' mode='r' encoding='UTF-8'>
test()

----------
components: Tests
files: formatter_fix_resource_warning.patch
keywords: patch
messages: 194260
nosy: vajrasky
priority: normal
severity: normal
status: open
title: Got ResourceWarning: unclosed file when using test function from formatter module
type: resource usage
versions: Python 3.4
Added file: http://bugs.python.org/file31138/formatter_fix_resource_warning.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 3, 2013, 6:51 AM

Post #2 of 11 (30 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Vajrasky Kok added the comment:

Sorry, I forgot about stdin. Attached the patch to handle stdin gracefully.

----------
Added file: http://bugs.python.org/file31139/formatter_fix_resource_warning_v2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 3, 2013, 7:04 AM

Post #3 of 11 (30 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Vajrasky Kok added the comment:

I guess I should not close stdin just in case people are using test function in the script.

Attached the patch to only close the open files not stdin.

----------
Added file: http://bugs.python.org/file31140/formatter_fix_resource_warning_v3.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 3, 2013, 7:44 AM

Post #4 of 11 (29 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Martijn Pieters added the comment:

Why is the `formatter` module still part of Python 3? This was a dependency for the `htmllib` module in Python 2 only, and that module was deprecated and removed from Python 3.

----------
nosy: +mjpieters

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2013, 1:35 PM

Post #5 of 11 (17 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

STINNER Victor added the comment:

"Why is the `formatter` module still part of Python 3? This was a dependency for the `htmllib` module in Python 2 only, and that module was deprecated and removed from Python 3."

The formatter module was deprecated? When?

----------
nosy: +haypo

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2013, 9:53 PM

Post #6 of 11 (13 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Benjamin Peterson added the comment:

Please wrap the "businesss" part of the test function in a try... finally. Otherwise the patch looks good.

----------
nosy: +benjamin.peterson

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 12:18 AM

Post #7 of 11 (14 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Vajrasky Kok added the comment:

Thanks, Benjamin, for reviewing my patch.

Attached the fourth patch to wrap the "business" part inside the try ... finally.

----------
Added file: http://bugs.python.org/file31237/formatter_fix_resource_warning_v4.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 12:32 AM

Post #8 of 11 (14 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Benjamin Peterson added the comment:

That will fail if fp is not assigned before an exception is raised. I mostly mean the part starting with the for loop.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 1:15 AM

Post #9 of 11 (11 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Vajrasky Kok added the comment:

Ah, sorry about that.

Attached the fifth patch to only wrap "for loop" section inside the try... finally.

----------
Added file: http://bugs.python.org/file31238/formatter_fix_resource_warning_v5.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 4:37 AM

Post #10 of 11 (11 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

Martijn Pieters added the comment:

> The formatter module was deprecated? When?

It wasn't, that's the point I am raising. The `formatter` module was exclusively used by the `htmllib` module, I am surprised the `formatter` module wasn't part of that deprecation.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 4:42 AM

Post #11 of 11 (11 views)
Permalink
[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module [In reply to]

R. David Murray added the comment:

Pydoc uses DumbWriter.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.