From a4120a879adf2b50dd18ed8a6310b9bae65f0209 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Thu, 17 Jan 2013 11:30:57 +0100 Subject: [PATCH] [IMP] long polling: disable the watchdog for the WorkerLongPolling, added command-line option for its port. bzr revid: vmt@openerp.com-20130117103057-12ez48kj48pntb1g --- openerp/service/workers.py | 12 ++++++++++-- openerp/tools/config.py | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/openerp/service/workers.py b/openerp/service/workers.py index 29ae9de10c0..7321978e859 100644 --- a/openerp/service/workers.py +++ b/openerp/service/workers.py @@ -35,6 +35,7 @@ class Multicorn(object): def __init__(self, app): # config self.address = (config['xmlrpc_interface'] or '0.0.0.0', config['xmlrpc_port']) + self.long_polling_address = (config['xmlrpc_interface'] or '0.0.0.0', config['longpolling_port']) self.population = config['workers'] self.timeout = config['limit_time_real'] self.limit_request = config['limit_request'] @@ -132,7 +133,8 @@ class Multicorn(object): def process_timeout(self): now = time.time() for (pid, worker) in self.workers.items(): - if now - worker.watchdog_time >= worker.watchdog_timeout: + if (worker.watchdog_timeout is not None) and \ + (now - worker.watchdog_time >= worker.watchdog_timeout): _logger.error("Worker (%s) timeout", pid) self.worker_kill(pid, signal.SIGKILL) @@ -185,7 +187,7 @@ class Multicorn(object): self.long_polling_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.long_polling_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.long_polling_socket.setblocking(0) - self.long_polling_socket.bind(('0.0.0.0', 8072)) + self.long_polling_socket.bind(self.long_polling_address) self.long_polling_socket.listen(8) def stop(self, graceful=True): @@ -230,6 +232,7 @@ class Worker(object): self.multi = multi self.watchdog_time = time.time() self.watchdog_pipe = multi.pipe_new() + # Can be set to None if no watchdog is desired. self.watchdog_timeout = multi.timeout self.ppid = os.getpid() self.pid = None @@ -345,6 +348,11 @@ class WorkerHTTP(Worker): class WorkerLongPolling(Worker): """ Long polling workers """ + def __init__(self, multi): + super(WorkerLongPolling, self).__init__(multi) + # Disable the watchdog feature for this kind of worker. + self.watchdog_timeout = None + def start(self): config.options["gevent"] = True _logger.info('Using gevent mode') diff --git a/openerp/tools/config.py b/openerp/tools/config.py index 83a347f0864..dcbf26783e3 100644 --- a/openerp/tools/config.py +++ b/openerp/tools/config.py @@ -121,6 +121,8 @@ class configmanager(object): help="disable the XML-RPC protocol") group.add_option("--proxy-mode", dest="proxy_mode", action="store_true", my_default=False, help="Enable correct behavior when behind a reverse proxy") + group.add_option("--longpolling-port", dest="longpolling_port", my_default=8072, + help="specify the TCP port for longpolling requests", type="int") parser.add_option_group(group) # XML-RPC / HTTPS @@ -378,7 +380,8 @@ class configmanager(object): self.options['pidfile'] = False # if defined dont take the configfile value even if the defined value is None - keys = ['xmlrpc_interface', 'xmlrpc_port', 'db_name', 'db_user', 'db_password', 'db_host', + keys = ['xmlrpc_interface', 'xmlrpc_port', 'longpolling_port', + 'db_name', 'db_user', 'db_password', 'db_host', 'db_port', 'db_template', 'logfile', 'pidfile', 'smtp_port', 'email_from', 'smtp_server', 'smtp_user', 'smtp_password', 'netrpc_interface', 'netrpc_port', 'db_maxconn', 'import_partial', 'addons_path',