Add thread number limit

This commit is contained in:
Cédric Krier committed 2008-04-27 17:09:13 +02:00
1 parent bca8a809ba
commit 95e9bf12b2
2 files changed
+11 -5

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ class ConfigManager(object):
'smtp_password': False,
'stop_after_init': False,
'data_path': '/var/lib/trytond',
'max_thread': 40,
}
parser = optparse.OptionParser(version=VERSION)
+10 -5
View File
@@ -332,7 +332,7 @@ class TinySocketClientThread(threading.Thread):
try:
msg = pysocket.receive()
except:
self.sock.close()
pysocket.disconnect()
self.threads.remove(self)
return False
if first:
@@ -394,10 +394,13 @@ class TinySocketServerThread(threading.Thread):
try:
self.running = True
while self.running:
(clientsocket, address) = self.socket.accept()
c_thread = TinySocketClientThread(clientsocket, self.threads, self.secure)
self.threads.append(c_thread)
c_thread.start()
if not int(CONFIG['max_thread']) \
or len(self.threads) < int(CONFIG['max_thread']):
(clientsocket, address) = self.socket.accept()
c_thread = TinySocketClientThread(clientsocket, self.threads,
self.secure)
self.threads.append(c_thread)
c_thread.start()
self.socket.close()
except Exception, exp:
self.socket.close()
@@ -426,6 +429,8 @@ class TinySocketServerThread(threading.Thread):
class BaseThreadedHTTPServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
max_children = CONFIG['max_thread']
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)