This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients jnoller, martin.panter, pitrou, serhiy.storchaka
Date 2015-11-18.12:20:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1447849211.72.0.295500270263.issue25654@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-11-18 12:20:11serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, jnoller, martin.panter
2015-11-18 12:20:11serhiy.storchakasetmessageid: <1447849211.72.0.295500270263.issue25654@psf.upfronthosting.co.za>
2015-11-18 12:20:11serhiy.storchakalinkissue25654 messages
2015-11-18 12:20:11serhiy.storchakacreate