SockerServer.TCPServer problem

huy nytimes at
Tue Aug 17 16:23:46 CEST 2004

Hi All,

Can someone explain why this bit of code can't keep up with some java 
code which spawns about 200 (threads) simultaneous connections each 
sending about 10 mesgs each. I basically don't get the 2000 connections 
i expect on the python side. I end up with some number very close on 
different runs eg. 1989, 1972, 1992 etc.

Any ideas ?



import socket
import struct
import time
import SocketServer
import thread
from datetime import datetime

import os
import datetime
import random


cnt = 0

class PDAHandler(SocketServer.BaseRequestHandler):
    def handle(self):
       global cnt

       cnt += 1
       s = self.request
       dlen = s.recv(4, socket.MSG_WAITALL)
       print "Received: ", dlen, cnt, " from ", s.getpeername()
       dataLen = struct.unpack("!i", dlen)
       data = s.recv(dataLen[0])
       f = file("aaa/recv%02d.txt" % cnt, "w+")

def start_servers():
    msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler)

if __name__ == "__main__":

More information about the Python-list mailing list