Warning
This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
Source code for galaxy.web_stack.transport
"""Web application stack operations
"""
import logging
import threading
log = logging.getLogger(__name__)
[docs]class ApplicationStackTransport:
SHUTDOWN_MSG = "__SHUTDOWN__"
[docs] def __init__(self, app, stack, dispatcher=None):
"""Pre-fork initialization."""
self.app = app
self.stack = stack
self.can_run = False
self.running = False
self.dispatcher = dispatcher
self.dispatcher_thread = None
def _dispatch_messages(self):
pass
[docs] def start_if_needed(self):
# Don't unnecessarily start a thread that we don't need.
if (
self.can_run
and not self.running
and not self.dispatcher_thread
and self.dispatcher
and self.dispatcher.handler_count
):
self.running = True
self.dispatcher_thread = threading.Thread(
name=f"{self.__class__.__name__}.dispatcher_thread", target=self._dispatch_messages
)
self.dispatcher_thread.start()
log.info("%s dispatcher started", self.__class__.__name__)
[docs] def stop_if_unneeded(self):
if (
self.can_run
and self.running
and self.dispatcher_thread
and self.dispatcher
and not self.dispatcher.handler_count
):
self.running = False
self.dispatcher_thread.join()
self.dispatcher_thread = None
log.info("%s dispatcher stopped", self.__class__.__name__)
[docs] def shutdown(self):
self.running = False
if self.dispatcher_thread:
log.info("Joining application stack transport dispatcher thread")
self.dispatcher_thread.join()
self.dispatcher_thread = None