New submission from Mark Gius: 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. ---------- components: Library (Lib) files: fd_leak_fix.diff keywords: patch messages: 173804 nosy: Mark.Gius priority: normal severity: normal status: open title: subprocess.Popen leaks file descriptors on os.fork() failure type: resource usage versions: Python 2.7 Added file: http://bugs.python.org/file27719/fd_leak_fix.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16327> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com