diff --git a/bin/service/netrpc_server.py b/bin/service/netrpc_server.py index 878a3da3ba8..ae1f4e8a8c1 100644 --- a/bin/service/netrpc_server.py +++ b/bin/service/netrpc_server.py @@ -37,13 +37,16 @@ class TinySocketClientThread(threading.Thread, netsvc.OpenERPDispatcher): self.sock = sock self.threads = threads + def __del__(self): + if self.sock: + self.sock.close() + def run(self): import select self.running = True try: ts = tiny_socket.mysocket(self.sock) except: - self.sock.close() self.threads.remove(self) return False while self.running: @@ -51,18 +54,27 @@ class TinySocketClientThread(threading.Thread, netsvc.OpenERPDispatcher): msg = ts.myreceive() except: self.sock.close() + self.sock = None self.threads.remove(self) return False try: result = self.dispatch(msg[0], msg[1], msg[2:]) ts.mysend(result) except netsvc.OpenERPDispatcherException, e: - new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling - ts.mysend(new_e, exception=True, traceback=e.traceback) + try: + new_e = Exception(tools.exception_to_unicode(e.exception)) # avoid problems of pickeling + ts.mysend(new_e, exception=True, traceback=e.traceback) + except: + pass + except Exception, e: + # this code should not be reachable, therefore we warn + netsvc.Logger().notifyChannel("net-rpc", netsvc.LOG_WARNING, "exception: %" % str(e)) + break - self.sock.close() - self.threads.remove(self) - return True + self.sock.close() + self.sock = None + self.threads.remove(self) + return True def stop(self): self.running = False @@ -71,7 +83,7 @@ class TinySocketClientThread(threading.Thread, netsvc.OpenERPDispatcher): class TinySocketServerThread(threading.Thread,netsvc.Server): def __init__(self, interface, port, secure=False): threading.Thread.__init__(self) - netsvc.Server.__init__(self) + netsvc.Server.__init__(self) self.__port = port self.__interface = interface self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -79,7 +91,7 @@ class TinySocketServerThread(threading.Thread,netsvc.Server): self.socket.bind((self.__interface, self.__port)) self.socket.listen(5) self.threads = [] - netsvc.Logger().notifyChannel("web-services", netsvc.LOG_INFO, + netsvc.Logger().notifyChannel("web-services", netsvc.LOG_INFO, "starting NET-RPC service at %s port %d" % (interface or '0.0.0.0', port,)) def run(self): @@ -91,8 +103,16 @@ class TinySocketServerThread(threading.Thread,netsvc.Server): ct = TinySocketClientThread(clientsocket, self.threads) self.threads.append(ct) ct.start() + lt = len(self.threads) + if (lt > 10) and (lt % 10 == 0): + # Not many threads should be serving at the same time, so log + # their abuse. + netsvc.Logger().notifyChannel("web-services", netsvc.LOG_DEBUG, + "Netrpc: %d threads" % len(self.threads)) self.socket.close() except Exception, e: + netsvc.Logger().notifyChannel("web-services", netsvc.LOG_WARNING, + "Netrpc: closing because of exception %s" % str(e)) self.socket.close() return False diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 6a8e8c9b094..93af5886320 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -108,12 +108,12 @@ def _eval_xml(self,node, pool, cr, uid, idref, context=None): all_timezones=[] pytz=pytzclass() idref2['pytz'] = pytz - try: + try: return eval(a_eval, idref2) - except: - logger = netsvc.Logger() - logger.notifyChannel("init", netsvc.LOG_WARNING, 'could eval(%s) for %s in %s, please get back and fix it!' % (a_eval,node.getAttribute('name'),context)) - return "" + except: + logger = netsvc.Logger() + logger.notifyChannel("init", netsvc.LOG_WARNING, 'could eval(%s) for %s in %s, please get back and fix it!' % (a_eval,node.getAttribute('name'),context)) + return "" if t == 'xml': def _process(s, idref): m = re.findall('[^%]%\((.*?)\)[ds]', s) @@ -243,12 +243,12 @@ class xml_import(object): id = xml_id if '.' in xml_id: module, id = xml_id.split('.', 1) - assert '.' not in id, """The ID reference "%s" must contains + assert '.' not in id, """The ID reference "%s" must contain maximum one dot. They are used to refer to other modules ID, in the form: module.record_id""" % (xml_id,) if module != self.module: modcnt = self.pool.get('ir.module.module').search_count(self.cr, self.uid, ['&', ('name', '=', module), ('state', 'in', ['installed'])]) - assert modcnt == 1, """The ID "%s" refer to an uninstalled module""" % (xml_id,) + assert modcnt == 1, """The ID "%s" refers to an uninstalled module""" % (xml_id,) if len(id) > 64: self.logger.notifyChannel('init', netsvc.LOG_ERROR, 'id: %s is to long (max: 64)'% (id,))