[IMP] netsvc/netrpc/http_server: introduce timeout for blocking server calls, sort of a busy wait

bzr revid: odo@openerp.com-20100713152244-9jdrem6b2xn50ltt
This commit is contained in:
Olivier Dony 2010-07-13 17:22:44 +02:00
parent 472693f703
commit 5d16cc715b
3 changed files with 9 additions and 2 deletions

View File

@ -318,6 +318,13 @@ class Server:
__is_started = False
__servers = []
# we don't want blocking server calls (think select()) to
# wait forever and possibly prevent exiting the process,
# but instead we want a form of polling/busy_wait pattern, where
# _server_timeout should be used as the default timeout for
# all I/O blocking operations
_busywait_timeout = 0.5
__logger = logging.getLogger('server')

View File

@ -120,6 +120,7 @@ class BaseHttpDaemon(threading.Thread, netsvc.Server):
self.server = ThreadedHTTPServer((interface, port), handler)
self.server.vdirs = []
self.server.logRequests = True
self.server.timeout = self._busywait_timeout
except Exception, e:
netsvc.Logger().notifyChannel(
'httpd', netsvc.LOG_CRITICAL,

View File

@ -115,8 +115,7 @@ class TinySocketServerThread(threading.Thread,netsvc.Server):
try:
self.running = True
while self.running:
timeout = self.socket.gettimeout()
fd_sets = select.select([self.socket], [], [], timeout)
fd_sets = select.select([self.socket], [], [], self._busywait_timeout)
if not fd_sets[0]:
continue
(clientsocket, address) = self.socket.accept()