httplib: memory leakage

butasan butasan97 at yahoo.com
Thu May 23 07:43:49 EDT 2002


I ran a simple client / server test program and used "top" to monitor the
memory usage at the client:

at the beginning:
  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
 7833 lab      16   0   2532 2532  1588 T     0.0  0.6   0:01 python2.2

when client's variable n = 333000:
  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
 7833 lab       18   0 23772  23M  1588 T    11.5  6.1   7:11 python2.2

The garbage collection didn't find any collectable object.

I didn't find memory problem at the server.  Both client and server
are Redhat 7.1 and python 2.2.  Do I use gc right?

Thank.

kk


With this client code:

import httplib
import sys
import time
import gc

n = 1

gc.set_debug(gc.DEBUG_LEAK)
gc.set_debug(gc.DEBUG_STATS)
gc.set_debug(gc.DEBUG_SAVEALL)
gc.enable()

while 1:
    connection = httplib.HTTPConnection('barney-lab:8800')
    connection.putrequest("GET", str(n))  #send something to server
#    time.sleep(5)
    print "n =", n
    n = n + 1
    connection.close()
    if not n%20:
        gc.collect()
        print gc.garbage

        if gc.garbage:
            sys.exit()
#    del gc.garbage[:]

The server code:

import SimpleHTTPServer
import BaseHTTPServer

class X(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        print "do get", self.path

def run(server_class=BaseHTTPServer.HTTPServer,
            handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
        server_address = ('', 8800)
        httpd = server_class(server_address, handler_class)
        print "waiting for requests"
        httpd.serve_forever()

run(handler_class = X)



More information about the Python-list mailing list