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 vstinner
Recipients martin.panter, pitrou, serhiy.storchaka, vstinner
Date 2016-04-12.22:49:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:07vstinnersetrecipients: + vstinner, pitrou, martin.panter, serhiy.storchaka
2016-04-12 22:49:07vstinnersetmessageid: <>
2016-04-12 22:49:07vstinnerlinkissue26741 messages
2016-04-12 22:49:07vstinnercreate