Message263281
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(). |
|
Date |
User |
Action |
Args |
2016-04-12 22:49:07 | vstinner | set | recipients:
+ vstinner, pitrou, martin.panter, serhiy.storchaka |
2016-04-12 22:49:07 | vstinner | set | messageid: <1460501347.41.0.70782898945.issue26741@psf.upfronthosting.co.za> |
2016-04-12 22:49:07 | vstinner | link | issue26741 messages |
2016-04-12 22:49:07 | vstinner | create | |
|