PageRenderTime 105ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/openerp/service/__init__.py

https://bitbucket.org/nagyv/openerp
Python | 104 lines | 35 code | 19 blank | 50 comment | 4 complexity | 77439813f0479c1dafc273d681ef315d MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import logging
  22. import threading
  23. import time
  24. import http_server
  25. import netrpc_server
  26. import web_services
  27. import websrv_lib
  28. import openerp.cron
  29. import openerp.modules
  30. import openerp.netsvc
  31. import openerp.osv
  32. import openerp.tools
  33. import openerp.wsgi
  34. #.apidoc title: RPC Services
  35. """ Classes of this module implement the network protocols that the
  36. OpenERP server uses to communicate with remote clients.
  37. Some classes are mostly utilities, whose API need not be visible to
  38. the average user/developer. Study them only if you are about to
  39. implement an extension to the network protocols, or need to debug some
  40. low-level behavior of the wire.
  41. """
  42. _logger = logging.getLogger(__name__)
  43. def start_services():
  44. """ Start all services.
  45. Services include the different servers and cron threads.
  46. """
  47. # Instantiate local services (this is a legacy design).
  48. openerp.osv.osv.start_object_proxy()
  49. # Export (for RPC) services.
  50. web_services.start_web_services()
  51. # Initialize the HTTP stack.
  52. #http_server.init_servers()
  53. #http_server.init_static_http()
  54. netrpc_server.init_servers()
  55. # Start the main cron thread.
  56. openerp.cron.start_master_thread()
  57. # Start the top-level servers threads (normally HTTP, HTTPS, and NETRPC).
  58. openerp.netsvc.Server.startAll()
  59. # Start the WSGI server.
  60. openerp.wsgi.core.start_server()
  61. def stop_services():
  62. """ Stop all services. """
  63. # stop scheduling new jobs; we will have to wait for the jobs to complete below
  64. openerp.cron.cancel_all()
  65. openerp.netsvc.Server.quitAll()
  66. openerp.wsgi.core.stop_server()
  67. config = openerp.tools.config
  68. _logger.info("Initiating shutdown")
  69. _logger.info("Hit CTRL-C again or send a second signal to force the shutdown.")
  70. logging.shutdown()
  71. # Manually join() all threads before calling sys.exit() to allow a second signal
  72. # to trigger _force_quit() in case some non-daemon threads won't exit cleanly.
  73. # threading.Thread.join() should not mask signals (at least in python 2.5).
  74. for thread in threading.enumerate():
  75. if thread != threading.currentThread() and not thread.isDaemon():
  76. while thread.isAlive():
  77. # Need a busyloop here as thread.join() masks signals
  78. # and would prevent the forced shutdown.
  79. thread.join(0.05)
  80. time.sleep(0.05)
  81. openerp.modules.registry.RegistryManager.delete_all()
  82. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: