/Library/lib/python3.7/site-packages/bokeh-1.4.0-py3.7.egg/bokeh/application/handlers/lifecycle.py

https://github.com/holzschu/Carnets
Python | 131 lines | 34 code | 22 blank | 75 comment | 0 complexity | c0ab638e857911ea9a6455de0399a559 MD5 | raw file
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2012 - 2019, Anaconda, Inc., and Bokeh Contributors.
  3. # All rights reserved.
  4. #
  5. # The full license is in the file LICENSE.txt, distributed with this software.
  6. #-----------------------------------------------------------------------------
  7. ''' Bokeh Application Handler to look for Bokeh server lifecycle callbacks
  8. in a specified Python module.
  9. '''
  10. #-----------------------------------------------------------------------------
  11. # Boilerplate
  12. #-----------------------------------------------------------------------------
  13. from __future__ import absolute_import, division, print_function, unicode_literals
  14. import logging
  15. log = logging.getLogger(__name__)
  16. #-----------------------------------------------------------------------------
  17. # Imports
  18. #-----------------------------------------------------------------------------
  19. # Standard library imports
  20. # External imports
  21. # Bokeh imports
  22. from .handler import Handler
  23. #-----------------------------------------------------------------------------
  24. # Globals and constants
  25. #-----------------------------------------------------------------------------
  26. __all__ = (
  27. 'LifecycleHandler',
  28. )
  29. #-----------------------------------------------------------------------------
  30. # General API
  31. #-----------------------------------------------------------------------------
  32. class LifecycleHandler(Handler):
  33. ''' Load a script which contains server lifecycle callbacks.
  34. '''
  35. def __init__(self, *args, **kwargs):
  36. super(LifecycleHandler, self).__init__(*args, **kwargs)
  37. self._on_server_loaded = _do_nothing
  38. self._on_server_unloaded = _do_nothing
  39. self._on_session_created = _do_nothing
  40. self._on_session_destroyed = _do_nothing
  41. self.safe_to_fork = True
  42. # Public methods ----------------------------------------------------------
  43. def modify_document(self, doc):
  44. ''' This handler does not make any modifications to the Document.
  45. Args:
  46. doc (Document) : A Bokeh Document to update in-place
  47. *This handler does not modify the document*
  48. Returns:
  49. None
  50. '''
  51. # we could support a modify_document function, might be weird though.
  52. pass
  53. def on_server_loaded(self, server_context):
  54. ''' Execute `on_server_unloaded`` from the configured module (if
  55. it is defined) when the server is first started.
  56. Args:
  57. server_context (ServerContext) :
  58. '''
  59. return self._on_server_loaded(server_context)
  60. def on_server_unloaded(self, server_context):
  61. ''' Execute ``on_server_unloaded`` from the configured module (if
  62. it is defined) when the server cleanly exits. (Before stopping the
  63. server's ``IOLoop``.)
  64. Args:
  65. server_context (ServerContext) :
  66. .. warning::
  67. In practice this code may not run, since servers are often killed
  68. by a signal.
  69. '''
  70. return self._on_server_unloaded(server_context)
  71. def on_session_created(self, session_context):
  72. ''' Execute ``on_session_created`` from the configured module (if
  73. it is defined) when a new session is created.
  74. Args:
  75. session_context (SessionContext) :
  76. '''
  77. return self._on_session_created(session_context)
  78. def on_session_destroyed(self, session_context):
  79. ''' Execute ``on_session_destroyed`` from the configured module (if
  80. it is defined) when a new session is destroyed.
  81. Args:
  82. session_context (SessionContext) :
  83. '''
  84. return self._on_session_destroyed(session_context)
  85. #-----------------------------------------------------------------------------
  86. # Dev API
  87. #-----------------------------------------------------------------------------
  88. #-----------------------------------------------------------------------------
  89. # Private API
  90. #-----------------------------------------------------------------------------
  91. def _do_nothing(ignored):
  92. pass
  93. #-----------------------------------------------------------------------------
  94. # Code
  95. #-----------------------------------------------------------------------------