[MERGE] merged long-polling branch:
authorVo Minh Thu <vmt@openerp.com>
Mon, 18 Feb 2013 15:32:25 +0000 (16:32 +0100)
committerVo Minh Thu <vmt@openerp.com>
Mon, 18 Feb 2013 15:32:25 +0000 (16:32 +0100)
When using --workers, an evented (for longpolling) worker is started.
When passing --gevent, all the server is evented but the cron is disabled.

bzr revid: vmt@openerp.com-20130218153225-w1yft9je0b15owdv

1  2 
openerp/service/wsgi_server.py

@@@ -94,7 -94,7 +94,7 @@@ def xmlrpc_handle_exception(e)
      if isinstance(e, openerp.osv.orm.except_orm): # legacy
          fault = xmlrpclib.Fault(RPC_FAULT_CODE_WARNING, openerp.tools.ustr(e.value))
          response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)
 -    elif isinstance(e, openerp.exceptions.Warning):
 +    elif isinstance(e, openerp.exceptions.Warning) or isinstance(e, openerp.exceptions.RedirectWarning):
          fault = xmlrpclib.Fault(RPC_FAULT_CODE_WARNING, str(e))
          response = xmlrpclib.dumps(fault, allow_none=False, encoding=None)
      elif isinstance (e, openerp.exceptions.AccessError):
@@@ -312,7 -312,7 +312,7 @@@ def http_to_wsgi(http_dir)
                  handler.auth_provider.checkRequest(handler, path)
              except websrv_lib.AuthRequiredExc, ae:
                  # Darwin 9.x.x webdav clients will report "HTTP/1.0" to us, while they support (and need) the
 -                # authorisation features of HTTP/1.1 
 +                # authorisation features of HTTP/1.1
                  if request_version != 'HTTP/1.1' and ('Darwin/9.' not in handler.headers.get('User-Agent', '')):
                      start_response("403 Forbidden", [])
                      return []
@@@ -426,7 -426,11 +426,11 @@@ def serve(interface, port, threaded)
      """
  
      global httpd
-     httpd = werkzeug.serving.make_server(interface, port, application, threaded=threaded)
+     if not openerp.evented:
+         httpd = werkzeug.serving.make_server(interface, port, application, threaded=threaded)
+     else:
+         from gevent.wsgi import WSGIServer
+         httpd = WSGIServer((interface, port), application)
      httpd.serve_forever()
  
  def start_service():
@@@ -446,8 -450,13 +450,13 @@@ def stop_service()
      The server is supposed to have been started by start_server() above.
      """
      if httpd:
-         httpd.shutdown()
-         close_socket(httpd.socket)
+         if not openerp.evented:
+             httpd.shutdown()
+             close_socket(httpd.socket)
+         else:
+             import gevent
+             httpd.stop()
+             gevent.shutdown()
  
  def close_socket(sock):
      """ Closes a socket instance cleanly