[IMP] openerp.service: import at the top.

bzr revid: vmt@openerp.com-20110924163358-svx1yjuwdybxxr6k
This commit is contained in:
Vo Minh Thu 2011-09-24 18:33:58 +02:00
parent 4268ca38b7
commit 58ebd45efe
1 changed files with 18 additions and 12 deletions

View File

@ -19,10 +19,18 @@
# #
############################################################################## ##############################################################################
import logging
import threading
import time
import http_server import http_server
import netrpc_server import netrpc_server
import web_services import web_services
import openerp.netsvc
import openerp.osv
import openerp.tools
#.apidoc title: RPC Services #.apidoc title: RPC Services
""" Classes of this module implement the network protocols that the """ Classes of this module implement the network protocols that the
@ -35,14 +43,15 @@ import web_services
""" """
def start_services(): def start_services():
import openerp """ Start all services.
http_server = openerp.service.http_server
netrpc_server = openerp.service.netrpc_server
Services include the different servers and cron threads.
"""
# Instantiate local services (this is a legacy design). # Instantiate local services (this is a legacy design).
openerp.osv.osv.start_object_proxy() openerp.osv.osv.start_object_proxy()
# Export (for RPC) services. # Export (for RPC) services.
openerp.service.web_services.start_web_services() web_services.start_web_services()
# Initialize the HTTP stack. # Initialize the HTTP stack.
http_server.init_servers() http_server.init_servers()
@ -57,10 +66,7 @@ def start_services():
openerp.netsvc.Server.startAll() openerp.netsvc.Server.startAll()
def stop_services(): def stop_services():
import openerp """ Stop all services. """
import logging
import threading
import time
openerp.netsvc.Agent.quit() openerp.netsvc.Agent.quit()
openerp.netsvc.Server.quitAll() openerp.netsvc.Server.quitAll()
config = openerp.tools.config config = openerp.tools.config
@ -69,14 +75,14 @@ def stop_services():
logger.info("Hit CTRL-C again or send a second signal to force the shutdown.") logger.info("Hit CTRL-C again or send a second signal to force the shutdown.")
logging.shutdown() logging.shutdown()
# manually join() all threads before calling sys.exit() to allow a second signal # Manually join() all threads before calling sys.exit() to allow a second signal
# to trigger _force_quit() in case some non-daemon threads won't exit cleanly. # to trigger _force_quit() in case some non-daemon threads won't exit cleanly.
# threading.Thread.join() should not mask signals (at least in python 2.5) # threading.Thread.join() should not mask signals (at least in python 2.5).
for thread in threading.enumerate(): for thread in threading.enumerate():
if thread != threading.currentThread() and not thread.isDaemon(): if thread != threading.currentThread() and not thread.isDaemon():
while thread.isAlive(): while thread.isAlive():
# need a busyloop here as thread.join() masks signals # Need a busyloop here as thread.join() masks signals
# and would present the forced shutdown # and would prevent the forced shutdown.
thread.join(0.05) thread.join(0.05)
time.sleep(0.05) time.sleep(0.05)