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 Mark.Gius
Recipients Mark.Gius
Date 2012-10-25.22:31:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1351204263.29.0.689540716038.issue16327@psf.upfronthosting.co.za>
In-reply-to
Content
When subprocess.Popen is called with subprocess.PIPE and os.fork() fails (due to insufficient memory for example), the pipes created by _get_handles() are not closed.

Steps to reproduce:

1) Launch a python shell, import subprocess
2) Create a situation where os.fork() will fail (I ran a program to eat up nearly all of the memory on a system)
3) subprocess.Popen('/bin/echo', stdin=subprocess.PIPE)
4) OSError(12, 'Cannot allocate memory')
5) ls /proc/$pid/fd , There are now extra pipes.

I tested on Ubuntu 11.10 python (2.7.2-5ubuntu1).  My reading of the 2.7 and 3.3 development trees suggest that this is an issue with both of those branches, but I don't have a 3.3 installation to confirm with.

I've attached a snippet that fixes it for my version of Python on Ubuntu.  No idea what ramifications it will have for other versions/OS/etc.  No automated testing included because I'm not entirely sure how to replicate this without eating up a ton of ram or doing something naughty with ulimit.
History
Date User Action Args
2012-10-25 22:31:03Mark.Giussetrecipients: + Mark.Gius
2012-10-25 22:31:03Mark.Giussetmessageid: <1351204263.29.0.689540716038.issue16327@psf.upfronthosting.co.za>
2012-10-25 22:31:03Mark.Giuslinkissue16327 messages
2012-10-25 22:31:02Mark.Giuscreate