Mailing List Archive

[issue15447] A file is not properly closed by webbrowser._invoke
New submission from Anton Barkovsky <swarmer.pm@gmail.com>:

webbrowser._invoke opens /dev/null, never closes it and a warning is
printed.

I'm attaching a patch.
The diff looks messy, but I'm just wrapping the code in a try-finally
block, the rest is just indented.

----------
components: Library (Lib)
files: fileclose.patch
keywords: patch
messages: 166392
nosy: anton.barkovsky
priority: normal
severity: normal
status: open
title: A file is not properly closed by webbrowser._invoke
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file26511/fileclose.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
R. David Murray <rdmurray@bitdance.com> added the comment:

Thanks. Is this warning printed by the webbrowser unit tests? If not can you see a way to add one that does?

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

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
Anton Barkovsky <swarmer.pm@gmail.com> added the comment:

The warning is printed by the file object when it closes itself in __del__:

ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r+' encoding='UTF-8'>

There isn't much to test, or is there?

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
Anton Barkovsky <swarmer.pm@gmail.com> added the comment:

To clarify, I discovered this when I was simply running webbrowser.open
in REPL.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
Ross Lagerwall <rosslagerwall@gmail.com> added the comment:

Are there any webbrowser unit tests?

(this could probably use the new subprocess.DEVNULL constant in 3.3)

----------
nosy: +rosslagerwall

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
R. David Murray <rdmurray@bitdance.com> added the comment:

@Anton: That's what I was guessing. If we had a unit test in test_webbrowser that did the same thing, we'd have seen the resource warning when running the tests and fixed it. However, it looks like there aren't *any* tests for webbrowser, not even in test_sundry (which just makes sure modules without tests are importable).

So adding a test that will trigger this resource warning requires setting up a test_webbrowser file first, even before we get to the problem of how to test something that wants to start up a web browser...(but that should be solvable with unittest.mock, I think).

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
Anton Barkovsky <swarmer.pm@gmail.com> added the comment:

Adding a patch that uses subprocess.DEVNULL instead.

Writing tests for webbrowser should be a separate issue, right?

----------
Added file: http://bugs.python.org/file26513/fileclose_devnull.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
R. David Murray <rdmurray@bitdance.com> added the comment:

You could do it either way. Normally we prefer to have a test along with any fix; in this case adding a test involves adding the test module as well, but it is not different in principle. If you want to work on it and prefer to have it as a separate issue that's fine, we'll just make the test issue dependent on this one.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
Anton Barkovsky added the comment:

An updated patch with the same issue fixed in Konqueror class.

----------
Added file: http://bugs.python.org/file26602/fileclose_devnull_v2.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue15447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue15447] A file is not properly closed by webbrowser._invoke [ In reply to ]
Anton Barkovsky added the comment:

Added tests in #15557.

----------

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