Serhiy Storchaka added the comment:
sys.stdin is set to open(os.devnull) in multiprocessing.forkserer and
multiprocessing.process (see issue5313). At shutdown stage sys.std* streams are
restored to sys.__std*__. Here the resource warning is emitted.
An example that demonstrates similar issue:
$ ./python -We -c 'import sys; sys.stdin = open("/dev/null")'
Exception ignored in: <_io.FileIO name='/dev/null' mode='rb' closefd=True>
ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r'
encoding='UTF-8'>
A workaround is to set sys.__stdin__ as well as sys.stdin. Now a resource
warning is no longer emitted at the stage of restoring standard streams, but it
can be randomly emitted at the stage of clearing sys dict (depending on the
order of deallocating stdin and stderr). The question is why a resource warning
is not emitted in normal case, with standard stdin.
Proposed patch closes sys.__stdin__ and set it to sys.stdin in multiprocessing,
makes standard streams cleanup at shutdown more reliable, and fixes two tests
that set sys.stderr.
----------
components: +Interpreter Core, Library (Lib)
keywords: +patch
nosy: +jnoller, pitrou, serhiy.storchaka
stage: -> patch review
versions: +Python 2.7, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file41068/cleanup_std_streams.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25654>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com