Bootstrap

odoo web机制

一、wsgi实现

    1.1 application

	路径:odoo.service.wsgi_server.application
	实现代码:
	def application(environ, start_response):
	    # FIXME: is checking for the presence of HTTP_X_FORWARDED_HOST really useful?
	    #        we're ignoring the user configuration, and that means we won't
	    #        support the standardised Forwarded header once werkzeug supports
	    #        it
	    if config['proxy_mode'] and 'HTTP_X_FORWARDED_HOST' in environ:
	        return ProxyFix(application_unproxied)(environ, start_response)
	    else:
	        return application_unproxied(environ, start_response)

    1.2 server

	负责启动wsgi,加载application()。odoo由三个类定义server,分别是ThreadedServer、
	PreforkServer、GeventServer,通过调用全局方法start来实现对application的启动,该方法路径
	odoo.service.server
def start(preload=None, stop=False):
    """ Start the odoo http server and cron processor.
    """
    global server

    load_server_wide_modules()
    odoo.service.wsgi_server._patch_xmlrpc_marshaller()
	#  
    if odoo.evented:
    	#  GeventServer启动app
        server = GeventServer(odoo.service.wsgi_server.application)
    elif config['workers']:
        if config['test_enable'] or config['test_file']:
            _logger.warning("Unit testing in workers mode could fail; use --workers 0.")
		#  PreforkServer启动app
        server = PreforkServer(odoo.service.wsgi_server.application)

        # Workaround for Python issue24291, fixed in 3.6 (see Python issue26721)
        if sys.version_info[:2] == (3,5):
            # turn on buffering also for wfile, to avoid partial writes (Default buffer = 8k)
            werkzeug.serving.WSGIRequestHandler.wbufsize = -1
    else:
    	# ThreadedServer启动app
        server = ThreadedServer(odoo.service.wsgi_server.application)

    watcher = None
    if 'reload' in config['dev_mode'] and not odoo.evented:
        if inotify:
            watcher = FSWatcherInotify()
            watcher.start()
        elif watchdog:
            watcher = FSWatcherWatchdog()
            watcher.start()
        else:
            if os.name == 'posix' and platform.system() != 'Darwin':
                module = 'inotify'
            else:
                module = 'watchdog'
            _logger.warning("'%s' module not installed. Code autoreload feature is disabled", module)
    if 'werkzeug' in config['dev_mode']:
        server.app =
;