Thread Memory Leak

Marco Catunda catunda at pobox.com
Tue Jun 25 14:37:12 CEST 2002


Hello,

I've developed a python program with some threads. 
This program is a daemon server. I have seen the
memory of that program growing very fast in a short 
period of time. So I decided to make a little program
to see what's happen.

########################################
import os
import threading

def runthread():
    a = 0
    for i in range(10):
        a += 1

while 1:
    listThread = []

    for i in range(50):
        listThread.append( threading.Thread( None, runthread ) )
    for i in listThread:
        i.start()
    for i in listThread:
        i.join()

    pid = os.getpid()
    print "==================================="
    os.system( "ps -o vsize,rss %d" % pid )
########################################

What's wrong with the above code? I don't know
why this code has memory leak. Take a look at
used memory, after 10 minutes of running the 
used memory grow.

regards

--
Marco Catunda



More information about the Python-list mailing list