Hi List, > >I am trying to write a simple threaded application which will simulate 1000 > >connections to a remote service in order to "stress test" that the remote > >service can handle that many connections. > [...] > >Is there a way to accomplish what I am trying to do, perhaps in a more > >memory-friendly way? > > Yes. You don't need one thread per connection: > http://docs.python.org/lib/module-asyncore.html
I am running into a problem where asyncore is through a filedescriptor error if I try to launch more that 1023 connections: ------------------------------------ Traceback (most recent call last): File "./test.py", line 46, in ? asyncore.loop() File "/usr/lib/python2.4/asyncore.py", line 192, in loop poll_fun(timeout, map) File "/usr/lib/python2.4/asyncore.py", line 122, in poll r, w, e = select.select(r, w, e, timeout) ValueError: filedescriptor out of range in select() ------------------------------------ Is there a limitation on the number of simultaneous connects that can be made with asyncore ? Attached is the updated source code. Thanks! -- Lee Leahu RICIS, Inc. Internet Technology Specialist 866-RICIS-77 Toll Free Voice (US) [EMAIL PROTECTED] 708-444-2690 Voice (International) http://www.ricis.com/ 866-99-RICIS Toll Free Fax (US) 708-444-2697 Fax (International) RICIS, Inc. is a member of the Public Safety Alliance Group This email and any attachments that are included in it have been scanned for malicious or inappropriate content and are believed to be safe.
#!/usr/bin/python import time import asyncore import socket print time.ctime() class telnet_client(asyncore.dispatcher): def __init__(self,count): asyncore.dispatcher.__init__(self) self.status = -1 self.count = count self.create_socket(socket.AF_INET, socket.SOCK_STREAM) print "attempt",count try: self.connect(("10.80.252.64", 22)) except: pass def handle_connect(self): pass def handle_read(self): data = self.recv(8192) data = data.replace("\n", "") data = data.replace("\r", "") if data == "SSH-2.0-OpenSSH_3.8p1": self.status = 0 self.close(); def handle_write(self): pass def handle_close(self): pass sshlist = [] for count in range (0,1022): c = telnet_client(count) sshlist.append(c) asyncore.loop() totalsuccess = 0 totalerror = 0 for ssh in sshlist: print "verifying",ssh.count if ssh.status == 0: totalsuccess += 1 else: totalerror += 1 print "Total Successes:",totalsuccess print "Total Errors:",totalerror print time.ctime()
-- http://mail.python.org/mailman/listinfo/python-list