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! -- http://mail.python.org/mailman/listinfo/python-list
Re: windows mem leak
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) -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows XP Installation
Smitsky wrote: Hi. I am a newbie to Python. I am running Win XP and want to know what the best course is for installing Python on my system. Could someone kindly direct me to some related resources? Thanks in advance, Steve It's really easy on Windows. Just download the install package and click on it. It only takes one, maybe two minutes top. It's safe to just accept the default settings. Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: windows mem leak
Peter Hansen wrote: Bob Smith wrote: Attached is the code. Run it yourself and see. You too Peter. Be gentle with me, this was my first attempt with threads. Thanks, Bob, and I will, but not before you answer some of my questions. I had good reasons to ask them, one of which is that I don't feel like wasting my time if, for example, you are using an older version of Python that *did* have a memory leak. 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] The most important answers you can provide will be versions, platform (pretty clearly Linux, but please confirm and give version), and what "bombs" means and how you are measuring the memory leak. WinXP Home, Service Pack 2, AMD 1400MHz proc, 256MB Ram Debian Linux Testing (2.4.28 vanilla Kernel) 3GHz P4 proc, 1.5GB Ram (I presume you're using a version of nmap that's compiled for Windows XP then? Yes, I am. It's certainly not standard. That's a matter of opinion. Nmap works fine on the WinXP machine. How have you proven that it is not *that* program which is at fault?) I have not. All I know is that on WinXP, the program uses 100% CPU at times and consumes more Ram than is available (the page file grows to 700 or 800MB). It runs OK for a few hours and then produces a 'not enough resources' error. And, the machine is generally unuserable. On Linux, it has no impact whatsoever on resources. Granted, the Linux machine is much more robust, but one wouldn't expect this great a difference. I can rewrite it so that it's pure Pyhton (no calling nmap) if you think that would be a good idea. Perhaps that would at least remove nmap from the equation. I can run it if you like and take a screen shot of the error. You'll have to give me a few hours though ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: a new Perl/Python a day
Scott Bryce wrote: Xah Lee wrote: frustrated constantly by its inanities and incompetences.) I don't see what this has to do with Perl. You're joking, right? -- http://mail.python.org/mailman/listinfo/python-list
Re: a new Perl/Python a day
Peter Maas wrote: Charlton Wilbur schrieb: "XL" == Xah Lee <[EMAIL PROTECTED]> writes: XL> i'll cross post to comp.lang.perl.misc and comp.lang.python. XL> If you spot mistakes, feel free to correct or discourse here. Error #1: crossposting to those two groups. (Error #2 is implying that you're a Perl expert, but someone else already pointed that out.) Xah Lee is the guy who used to fight Unixism some time ago thereby producing an extremly long and useless thread in this group. Now he's fighting Perl :) Please stop answering him if you don't want to waste your time. With terms such as "blabbering Unix donkeys" and "sloppy perl monkeys" Xah's articles are very entertaining. He has some valid points as well... he just presents them in anti-social ways. -- http://mail.python.org/mailman/listinfo/python-list
Re: protecting the python code.
nell wrote: Hi Steve, First the "10x in advance" means thanks in advance. The main importance of protecting my code is to save headache of customers that want to be smart and change it and then complain on bugs and problems. 10x I'd say that's more of a policy issue than a technical issue. You have a contract or agreement with your customers, right? Just place a cluase in it that addresses your concerns. You don't have to support people who have altered your code... nor should they expect to be supported. -- http://mail.python.org/mailman/listinfo/python-list
Re: python mode indentation problem
Xah Lee wrote: © ok, here's the ordeal. © © for i in range(5): © print i © for i in range(2): © print i, 'tt' © for i in [3]: © print i © for i in [32]: © print i © © # 1 level, 4 space © # 2 level, 1 tab © # 3 level, 1 tab, 4 spaces © # 4 level, 2 tabs. © © who the fuck coded the python mode in emacs? fuckhead please peruse: © http://xahlee.org/UnixResource_dir/writ/responsible_license.html I hope you never need a favor or interview for a job with someone who reads news groups. You're committing eSuicide by posting insulting rants such as this. All you accomplish is to isolate yourself. Try to be friendly. Ideas are only half the battle... presentation is the other half. You have some good and valid ideas, but your presentation is offensive and condescending. Your ideas are like golden coins wrapped in horse shit. Personally, I've had enough of your horse shit... perhaps I speak for others as well. -- http://mail.python.org/mailman/listinfo/python-list
file copy portability
Is shutil.copyfile(src,dst) the *most* portable way to copy files with Python? I'm dealing with plain text files on Windows, Linux and Mac OSX. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: file copy portability
John Machin wrote: Bob Smith wrote: Is shutil.copyfile(src,dst) the *most* portable way to copy files with Python? I'm dealing with plain text files on Windows, Linux and Mac OSX. Thanks! Portable what? Way of copying?? Do you want your files transferred (a) so that they look like native text files on the destination system, or (b) so that they are exact byte-wise copies? A 5-second squint at the source (Lib/shutil.py) indicates that it provides, reliably and portably, option b: fsrc = open(src, 'rb') fdst = open(dst, 'wb') One way of doing option (a): you would need to be running Python on the destination system, open the src file with 'rU', open the dst file with 'w'. The files are not copied from one platform to the other. The app must run on all platforms. I want to make the app as portable as possible to reduce platform specific code. -- http://mail.python.org/mailman/listinfo/python-list
list item's position
Hi, I have a Python list. I can't figure out how to find an element's numeric value (0,1,2,3...) in the list. Here's an example of what I'm doing: for bar in bars: if 'str_1' in bar and 'str_2' in bar: print bar This finds the right bar, but not its list position. The reason I need to find its value is so I can remove every element in the list before it so that the bar I found somewhere in the list becomes element 0... does that make sense? Thanks, Bob -- http://mail.python.org/mailman/listinfo/python-list
getting file size
Are these the same: 1. f_size = os.path.getsize(file_name) 2. fp1 = file(file_name, 'r') data = fp1.readlines() last_byte = fp1.tell() I always get the same value when doing 1. or 2. Is there a reason I should do both? When reading to the end of a file, won't tell() be just as accurate as os.path.getsize()? Thanks guys, Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050121 file reading & writing
Xah Lee wrote: # reading entire file as a list, of lines # mylist = f.readlines() To do this efficiently on a large file (dozens or hundreds of megs), you should use the 'sizehint' parameter so as not to use too much memory: sizehint = 0 mylist = f.readlines(sizehint) -- http://mail.python.org/mailman/listinfo/python-list
Re: [perl-python] 20050121 file reading & writing
Erik Max Francis wrote: Bob Smith wrote: To do this efficiently on a large file (dozens or hundreds of megs), you should use the 'sizehint' parameter so as not to use too much memory: sizehint = 0 mylist = f.readlines(sizehint) It doesn't make any difference. .readlines reads the entire file into memory at once. Are you sure, the docs say this: "f.readlines() returns a list containing all the lines of data in the file. If given an optional parameter sizehint, it reads that many bytes from the file and enough more to complete a line, and returns the lines from that. This is often used to allow efficient reading of a large file by lines, but without having to load the entire file in memory. Only complete lines will be returned." http://docs.python.org/tut/node9.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Another scripting language implemented into Python itself?
Rocco Moretti wrote: Python's also dangerous. Every time you do an "import module", you put your system at risk of crashing, having the hard-drive wiped Have you been drinking again? -- http://mail.python.org/mailman/listinfo/python-list