Leaks in subprocess.Popen

Ziga Seilnacht ziga.seilnacht at gmail.com
Wed Sep 20 16:13:23 EDT 2006


zloster wrote:
> I'm using Python 2.4.3 for Win32.
> I was trying to run a few child processes simultaneously in separate
> threads and get their STDOUT, but the program was leaking memory and I
> found that it was because of subprocess operating in another thread.
> The following code works fine, but I get a leaking handle every second.
> You can see it in the task manager if you choose to see the <handle
> count> column. Does anybody have a solution? Please help!
>

This bug is fixed in the 2.5 version of Python and will be fixed in the
next 2.4 maintainance release (2.4.4). See:
http://www.python.org/sf/1500293 for the bug report.

You can find the relevant changes here:
http://mail.python.org/pipermail/python-checkins/2006-June/053417.html
http://mail.python.org/pipermail/python-checkins/2006-June/053418.html

If you have Python Win32 Extensions installed you can try using that
instead of the extension in the standard library; you have to change a
single line in the subprocess module:

--- subprocess_modified.py	2006-09-20 22:04:29.734375000 +0200
+++ subprocess.py	2006-09-20 22:01:52.296875000 +0200
@@ -350,7 +350,7 @@
 if mswindows:
     import threading
     import msvcrt
-    if 0: # <-- change this to use pywin32 instead of the _subprocess
driver
+    if 1: # <-- change this to use pywin32 instead of the _subprocess
driver
         import pywintypes
         from win32api import GetStdHandle, STD_INPUT_HANDLE, \
                              STD_OUTPUT_HANDLE, STD_ERROR_HANDLE



Hope this helps,
Ziga




More information about the Python-list mailing list