上次说到,运行如下代码:
rc = odoo.service.server.start(preload=preload, stop=stop)#————又调用了odoo/service/server.py下的start函数啦 去到odoo10/odoo/service/server.py下查看定义的一个全局函数:
def start(preload=None, stop=False): """ Start the odoo http server and cron processor. """ global server #使用全局变量 server load_server_wide_modules() #加载openerp的一些模块 if odoo.evented: server = GeventServer(odoo.service.wsgi_server.application) elif config['workers']: server = PreforkServer(odoo.service.wsgi_server.application) else: server = ThreadedServer(odoo.service.wsgi_server.application) watcher = None if 'reload' in config['dev_mode']: if watchdog: watcher = FSWatcher() watcher.start() else: _logger.warning("'watchdog' module not installed. Code autoreload feature is disabled”) if 'werkzeug' in config['dev_mode']: server.app = DebuggedApplication(server.app, evalex=True) rc = server.run(preload, stop) # like the legend of the phoenix, all ends with beginnings if getattr(odoo, 'phoenix', False): if watcher: watcher.stop() _reexec() return rc if rc else 0
这样吧,我们按照函数运行流程,从上往下依次进行分析,
global server #使用了全局变量server.
在该文件上下文中可以看到,server = None , 是一个空对象
接下来调用该文件中的一个全局函数:load_server_wide_modules
其函数源码为:
def load_server_wide_modules(): for m in odoo.conf.server_wide_modules: try: odoo.modules.module.load_openerp_module(m) except Exception: msg = '' if m == 'web': msg = """The `web` module is provided by the addons found in the `openerp-web` project.Maybe you forgot to add those addons in your addons_path configuration.""" _logger.exception('Failed to load server-wide module `%s`.%s', m, msg)通过嵌套了这个print "in load_server_wide_modules ",m 这条测试语句,看到odoo.conf.server_wide_modules有2个对象,分别为web和web_kanban
接下来运行了odoo.modules.module.load_openerp_module(m)函数,找到odoo/modules/module.py下的load_openerp_module函数,这是个全局函数:
def load_openerp_module(module_name): """ Load an OpenERP module, if not already loaded. This loads the module and register all of its models, thanks to either the MetaModel metaclass, or the explicit instantiation of the model. This is also used to load server-wide module (i.e. it is also used when there is no model to register). """ global loaded #全局变量loaded是一个列表,存储着已经load的模块 if module_name in loaded: #如果已经加载就不用再加载了,直接return return initialize_sys_path() #初始化路径 try: __import__('odoo.addons.' + module_name) # Call the module's post-load hook. This can done before any model or # data has been initialized. This is ok as the post-load hook is for # server-wide (instead of registry-specific) functionalities. info = load_information_from_description_file(module_name) if info['post_load']: getattr(sys.modules['odoo.addons.' + module_name], info['post_load'])() except Exception, e: msg = "Couldn't load module %s" % (module_name) _logger.critical(msg) _logger.critical(e) raise else: loaded.append(module_name)
也就是说load_openerp_module
这个函数大概就是找找路径,确认加载我们需要加载的模块。
接下来选择服务器模式,我们这里是进入了 ThreadedServer,ThreadedServer是在odoo/service/server.py下声明的一个类,主要用于管理线程
使用watcher,可以实现Code autoreload,不过在我现行使用中并没有配置reload这个功能,因为可以发现我的odoo中的config[‘dev’]是空的。
进入 rc = server.run(preload, stop) 语句———服务器启动啰。
接下来的几条代码行都是有关服务器退出的啦。下一次我们将观察一下这个ThreadedServer是如何实现线程管理的吧!
---------------------
作者:清楼小刘
来源:CSDN
原文:https://blog.csdn.net/qq_33826977/article/details/76743481
版权声明:本文为博主原创文章,转载请附上博文链接!