[New-bugs-announce] [issue26741] subprocess.Popen should emit a ResourceWarning in destructor if the process is still running
STINNER Victor
report at bugs.python.org
Tue Apr 12 18:49:07 EDT 2016
New submission from STINNER Victor:
A subprocess.Popen object contains many resources: pipes, a child process (its pid, and an handle on Windows), etc.
IMHO it's not safe to rely on the destructor to release all resources. I would prefer to release resources explicitly. For example, use proc.wait() or "with proc:".
Attached patch emits a ResourceWarning in Popen destructor if the status of the child process was not read yet.
The patch changes also _execute_child() to set the returncode on error, if the child process raised a Python exception. It avoids to emit a ResourceWarning on this case.
The patch fixes also unit tests to release explicitly resources. self.addCleanup(p.stdout.close) is not enough: use "with proc:" instead.
TODO: fix also the Windows implementation of _execute_child().
----------
components: Library (Lib)
messages: 263281
nosy: haypo, martin.panter, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: subprocess.Popen should emit a ResourceWarning in destructor if the process is still running
type: resource usage
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26741>
_______________________________________
More information about the New-bugs-announce
mailing list