windows mem leak

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Smith

    #1

    windows mem leak

    Does the Win32 port of Python have a memory leak? I have some code that
    runs flawlessly on Linux, but bombs after a few hours on Windows. It's
    threaded and uses a lot of memory.

    Thanks!
  • Peter Hansen

    #2
    Re: windows mem leak

    Bob Smith wrote:[color=blue]
    > Does the Win32 port of Python have a memory leak? I have some code that
    > runs flawlessly on Linux, but bombs after a few hours on Windows. It's
    > threaded and uses a lot of memory.[/color]

    Let's see what you're missing:

    1. platform specifics
    2. versions of things involved
    3. any sort of detail about the code
    4. how you're noticing/measuring the problem
    5. what "bombs" means
    6. any mention that you've checked Sourceforge to see whether
    a similar problem has been reported

    There have been memory leaks in various past versions of Python,
    and could easily be in the current version, but they're generally
    rather specific in terms of the code that can trigger it. Once it
    was doing some particular work with a socket, once it was trying to
    append (or extend?) to an empty list, and so on.

    There are also a few ways you could have written your application
    to cause memory to leak as a result of your own code, not as a
    result of Python's. And it's even possible that this would happen
    only on one platform (though I'm trying hard to think of an example
    and can't... maybe it's very unlikely.)

    -Peter

    Comment

    • Steve Holden

      #3
      Re: windows mem leak

      Bob Smith wrote:
      [color=blue]
      > Does the Win32 port of Python have a memory leak? I have some code that
      > runs flawlessly on Linux, but bombs after a few hours on Windows. It's
      > threaded and uses a lot of memory.
      >
      > Thanks![/color]

      Yes, that's a well-known problem. Code that runs with a few errors will
      port without any trouble at all to Windows, but once it runs flawlessly
      on Linux it starts to leak memory on Windows. The PSU suspects a plot in
      Redmond, the basic details of which ar
      --
      Steve Holden http://www.holdenweb.com/
      Python Web Programming http://pydish.holdenweb.com/
      Holden Web LLC +1 703 861 4237 +1 800 494 3119

      Comment

      • Bob Smith

        #4
        Re: windows mem leak

        Steve Holden wrote:[color=blue]
        > Bob Smith wrote:
        >[color=green]
        >> Does the Win32 port of Python have a memory leak? I have some code
        >> that runs flawlessly on Linux, but bombs after a few hours on Windows.
        >> It's threaded and uses a lot of memory.
        >>
        >> Thanks![/color]
        >
        >
        > Yes, that's a well-known problem. Code that runs with a few errors will
        > port without any trouble at all to Windows, but once it runs flawlessly
        > on Linux it starts to leak memory on Windows. The PSU suspects a plot in
        > Redmond, the basic details of which ar[/color]

        Oh, the humor of it all ;)

        Attached is the code. Run it yourself and see. You too Peter. Be gentle
        with me, this was my first attempt with threads.

        import os
        import urllib
        import socket
        import time
        import Queue
        import threading

        ############### ############### ############
        # Network Section #
        ############### ############### ############

        socket.setdefau lttimeout(30)

        networks = []
        hosts = []
        subnets = []

        # Add the network 192.168.0 possibility to networks.
        networks.append ("192.168.0. ")

        # Generate and add networks 192.168.1-255 to networks.
        n = 0
        while n < 255:
        n = n + 1
        networks.append ("192.168.%s ." %(n))

        # Generate and add hosts 1-254 to hosts.
        for network in networks:
        h = 1
        # Add the n.n.n.0 host possibility to hosts.
        hosts.append(ne twork+str(h))
        while h < 254:
        h = h + 1
        hosts.append(ne twork+str(h))

        # This should equal 65024 or 256 * 254
        # because 256 possibilities are OK in the 3rd octet,
        # but only 254 possibilities are OK in the 4th octet...
        # we exclude 0 and 255.
        print "There are", len(hosts), "total hosts (192.168.256*25 4) in the hosts list."

        a = 0
        b = 254

        ## Add the 192.168.0 net list to the subnets list.
        subnets.append( hosts[0:254])
        ##print subnets
        ##print len(subnets)

        ## Add the 192.168.1-254 net lists to the subnets list.
        for x in xrange(254):
        a = a+254
        b = b+254
        subnets.append( hosts[a:b])
        ##print subnets
        ##print len(subnets)

        ## Add the 192.168.255 net list to the subnets list.
        subnets.append( hosts[64770 :65024])
        ##print subnets[0]
        print "There are", len(subnets), "class C network lists in the subnets list."

        ############### ############### ############
        # Queue Section #
        ############### ############### ############

        # Create a queue of urls to feed the threads
        # Make it so that the queue only contains 256 items

        nmap_queue = Queue.Queue(256 )
        for subnet in subnets:
        nmap_queue.put( subnet)

        ############### ############### #############
        # Thread Section #
        ############### ############### #############

        class prac(threading. Thread):

        def run(self):
        net = nmap_queue.get( )
        for ip in net:
        Y = os.popen('nmap -sT -p 80 -P0 -n %s' %ip)
        data = Y.read()
        Y.close()
        if 'open' in data:
        O = file('opened.tx t', 'a')
        print >> O, ip
        O.close()
        elif 'closed' in data:
        C = file('closed.tx t', 'a')
        print >> C, ip
        C.close()
        elif 'filtered' in data:
        F = file('filtered. txt' , 'a')
        print >> F, ip
        F.close()
        else:
        V = file('other.txt ', 'a')
        print >> V, data, ip
        V.close()

        threads = []
        for i in xrange(256):
        go = prac()
        threads.append( go)
        for thread in threads:
        thread.start()
        while threading.activ eCount() > 1:
        print str(threading.a ctiveCount()), "threads running incl. main"
        time.sleep(1)

        Comment

        • Bulba!

          #5
          Re: windows mem leak

          On Sat, 08 Jan 2005 15:00:05 -0500, Steve Holden <steve@holdenwe b.com>
          wrote:
          [color=blue][color=green]
          >> Does the Win32 port of Python have a memory leak? I have some code that
          >> runs flawlessly on Linux, but bombs after a few hours on Windows. It's
          >> threaded and uses a lot of memory.[/color][/color]
          [color=blue]
          >Yes, that's a well-known problem. Code that runs with a few errors will
          >port without any trouble at all to Windows, but once it runs flawlessly
          >on Linux it starts to leak memory on Windows. The PSU suspects a plot in
          >Redmond, the basic details of which ar[/color]

          You have my nomination for SOTW*. :-)

          * skit of the week / short story of the week




          --
          It's a man's life in a Python Programming Association.

          Comment

          Working...