Serhiy Storchaka added the comment:

> Oops, I forgot to discuss the second part :-) You also added "sys.__stderr__ 
> = sys.stderr" in multiprocessing.

At the start of PyImport_Cleanup() sys.stdXXX is set to sys.__stdXXX__. If 
sys.stdXXX is not sys.__stdXXX__ and here is the last reference to the stream, 
this causes deallocating sys.stdXXX and emitting a resource warning. If set 
sys.__stdXXX__ to sys.stdXXX, deallocating the stream is deferred to the end of 
PyImport_Cleanup(). Other changes make PyImport_Cleanup() to close standard 
streams explicitly before deallocating, thus resource warning are not emitted.

This workaround is not needed if deallocating sys.stdin doesn't emit a resource 
warning (since it is opened with closefd=False). But it still may be needed in 
tests if apply proposed changes to PyImport_Cleanup(), since sys.stderr is set 
to a file opened with closefd=True.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25654>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to