Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Leaks in subprocess.Popen

Reply
Thread Tools

Leaks in subprocess.Popen

 
 
zloster
Guest
Posts: n/a
 
      09-20-2006
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!

import subprocess, time, thread

def comm(command):
run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = run.communicate()
print out

while 1:
thread.start_new_thread(comm, ("dir",))
time.sleep(1)

 
Reply With Quote
 
 
 
 
Ziga Seilnacht
Guest
Posts: n/a
 
      09-20-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/pyt...ne/053417.html
http://mail.python.org/pipermail/pyt...ne/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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
leaks unloading AppDomain greg ASP .Net 1 06-13-2005 12:45 PM
Website to Test for Security Leaks Herb Firefox 3 04-18-2005 01:48 PM
ASP.NET - Detecting memory leaks ASP.Confused ASP .Net 2 07-16-2004 04:24 PM
TextReader in Cache Leaks? Chan ASP .Net 3 11-10-2003 01:43 PM
memory leaks with firebird? astromannix Firefox 2 07-26-2003 12:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57