Author: sleon
Date: 2006-01-09 11:52:31 +0000 (Mon, 09 Jan 2006)
New Revision: 7824

Modified:
   trunk/apps/freeviz/server.py
Log:
added a max to the number of a from client dataaccepting threads per time, all 
other connections will be queueueueuened, max queueue length is 100

Modified: trunk/apps/freeviz/server.py
===================================================================
--- trunk/apps/freeviz/server.py        2006-01-09 11:31:49 UTC (rev 7823)
+++ trunk/apps/freeviz/server.py        2006-01-09 11:52:31 UTC (rev 7824)
@@ -7,6 +7,7 @@
 PORT=23415
 NRCONS=100
 DELAY=10
+MAXRUNNING=10



@@ -14,6 +15,7 @@
        vlock = threading.Lock()
        chunks=[]
        id=0
+       running=0

 class Handler(Base):

@@ -49,6 +51,10 @@
                Base.chunks.append(self.chunk)
                Base.vlock.release()    
                print "%s\n________\n" % self.chunk
+               Base.vlock.acquire()
+               assert Base.running > 0
+               Base.running -= 1
+               Base.vlock.release


 lstn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -58,10 +64,17 @@
 h.start()

 while 1:
-       (clnt,ap) = lstn.accept()
-       s = serv(clnt)
-       s.start()       
+       Base.vlock.acquire()
+       running = Base.running
+       Base.vlock.release()
+       if running < MAXRUNNING:
+               (clnt,ap) = lstn.accept()
+               s = serv(clnt)
+               s.start()       
+               Base.vlock.acquire()
+               Base.running += 1
+               Base.vlock.release()
+       else:
+               time.sleep(1)


-
-


Reply via email to