473,320 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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!
Jul 18 '05 #1
4 1720
Bob Smith wrote:
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.


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
Jul 18 '05 #2
Bob Smith wrote:
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!


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
Jul 18 '05 #3
Steve Holden wrote:
Bob Smith wrote:
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!

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


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.setdefaulttimeout(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(network+str(h))
while h < 254:
h = h + 1
hosts.append(network+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*254) 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.txt', 'a')
print >> O, ip
O.close()
elif 'closed' in data:
C = file('closed.txt', '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.activeCount() > 1:
print str(threading.activeCount()), "threads running incl. main"
time.sleep(1)

Jul 18 '05 #4
On Sat, 08 Jan 2005 15:00:05 -0500, Steve Holden <st***@holdenweb.com>
wrote:
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.
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


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.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
1
by: iceColdFire | last post by:
Hi, I have been using mPatrol for sometime now...I want the tool to check on memeory leaks and other memory nicthes in my VC++ 6.0 programs... Does it run on Windows Intel X86 combo... If...
3
by: wavelet | last post by:
a.exe is one programming writen with c/c++ language. a.exe will be called multi-times by another programming. Now I want to check how much memory is used by a.exe or whether some memory leak...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: Jos Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
5
by: bluter | last post by:
We have server components which were created by a third party and compiled in VC++5 (sp3). They run fine on NT4 and 2000, however during testing of our migration to Server 2003, these components...
4
by: Niron kag | last post by:
Hi, I have a windows service, which is currently installed, on my local computer. The problem is that when I look at the task manager, I see that the “Mem Usage”, become bigger and bigger....
7
by: multicherry | last post by:
Hi, Having searched for a way to fetch a window object by name, all I came across were answers along the line of... "All you have to do is say windowObj = window.open("blah", "name");" which...
9
by: melmack3 | last post by:
Hi I have a big problem with shell commands execution via PHP. I have written a very short PHP script ilustrating the problem: <?php for($i=0;$i<1000;$i++) { exec("test.bat");
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.