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.

galaxy.webapps.galaxy package

Subpackages

Submodules

galaxy.webapps.galaxy.buildapp module

Provides factory methods to assemble the Galaxy web application

class galaxy.webapps.galaxy.buildapp.GalaxyWebApplication(galaxy_app: MinimalApp, session_cookie: str = 'galaxysession', name: str | None = None)[source]

Bases: WebApplication

injection_aware: bool = True
client_match: dict[str, str] | None = {'action': 'client', 'controller': 'root'}
__init__(galaxy_app: MinimalApp, session_cookie: str = 'galaxysession', name: str | None = None) → None[source]

Create a new web application object. To actually connect some controllers use add_controller and add_route. Call finalize_config when all controllers and routes have been added and __call__ to handle a request (WSGI style).

galaxy.webapps.galaxy.buildapp.app_factory(*args, **kwargs)[source]

Return a wsgi application serving the root object

galaxy.webapps.galaxy.buildapp.app_pair(global_conf, load_app_kwds=None, wsgi_preflight=True, **kwargs)[source]

Return a wsgi application serving the root object and the Galaxy application.

When creating an app for asgi, set wsgi_preflight to False to allow FastAPI middleware to handle CORS options, etc..

galaxy.webapps.galaxy.buildapp.postfork_setup()[source]
galaxy.webapps.galaxy.buildapp.populate_api_routes(webapp: WebApplication, app: MinimalApp)[source]
galaxy.webapps.galaxy.buildapp.wrap_in_middleware(app, global_conf, application_stack, **local_conf)[source]

Based on the configuration wrap app in a set of common and useful middleware.

galaxy.webapps.galaxy.fast_app module

galaxy.webapps.galaxy.fast_app.add_galaxy_middleware(app: FastAPI, gx_app)[source]
galaxy.webapps.galaxy.fast_app.initialize_fast_app(gx_wsgi_webapp, gx_app)[source]

Build the FastAPI app that fronts the Galaxy web server.

galaxy.webapps.galaxy.fast_factory module

Module containing factory class for building uvicorn app for Galaxy.

Information on uvicorn, its various settings, and how to invoke it can be found at https://www.uvicorn.org/.

Galaxy can be launched with uvicorn using the following invocation:

uvicorn --app-dir lib --factory galaxy.webapps.galaxy.fast_factory:factory

Use the environment variable GALAXY_CONFIG_FILE to specify a Galaxy configuration file. Galaxy configuration can be loading from a YAML or an .ini file (reads app:main currently but can be overridden with GALAXY_CONFIG_SECTION).

GALAXY_CONFIG_FILE=config/galaxy.yml uvicorn --app-dir lib --factory galaxy.webapps.galaxy.fast_factory:factory

Note

Information on additional ways to configure uvicorn can be found at https://www.uvicorn.org/.

Warning

If an ini file is supplied via GALAXY_CONFIG_FILE, the server properties such as host and port are not read from the file like older forms of configuring Galaxy.

Gunicorn is a server with more complex management options.

This factory function can be executed as a uvicorn worker managed with gunicorn with the following command-line.

gunicorn 'galaxy.webapps.galaxy.fast_factory:factory()' --env GALAXY_CONFIG_FILE=config/galaxy.ini --pythonpath lib -w 4 -k uvicorn.workers.UvicornWorker --config lib/galaxy/web_stack/gunicorn_config.py
class galaxy.webapps.galaxy.fast_factory.GalaxyWebApp(galaxy_app: UniverseApplication, wsgi_app: Any, asgi_app: FastAPI)[source]

Bases: object

The application objects assembled for a Galaxy web process.

galaxy_app: UniverseApplication
wsgi_app: Any
asgi_app: FastAPI
__init__(galaxy_app: UniverseApplication, wsgi_app: Any, asgi_app: FastAPI) → None
galaxy.webapps.galaxy.fast_factory.build_galaxy_web_app(galaxy_config: ~collections.abc.Mapping[str, ~typing.Any] | None = None, *, global_conf: ~collections.abc.Mapping[str, ~typing.Any] | None = None, load_app_kwds: ~collections.abc.Mapping[str, ~typing.Any] | None = None, wsgi_preflight: bool = False, register_shutdown_at_exit: bool = True, init_fast_app: ~collections.abc.Callable[[~typing.Any, ~galaxy.app.UniverseApplication], ~fastapi.applications.FastAPI] = <function initialize_fast_app>) → GalaxyWebApp[source]

Build Galaxy’s application objects from programmatic configuration.

Unlike the uvicorn factory below, this entry point does not require a configuration file or environment-variable setup. It also returns the underlying Galaxy application so embedding callers can own its lifecycle. Application construction exceptions are allowed to propagate to the caller.

galaxy.webapps.galaxy.fast_factory.factory()[source]

galaxy.webapps.galaxy.workers module

Gunicorn worker class used to run the Galaxy ASGI application.

uvicorn’s gunicorn worker makes two choices that together turn an ordinary worker recycle (--max-requests) into an unexplained core dump:

  • Server.shutdown() waits indefinitely for in-flight requests, because timeout_graceful_shutdown is never set, and it stops notifying the arbiter while it waits (callback_notify only fires from main_loop, which has already exited). The arbiter eventually decides the worker is hung.

  • init_signals() resets SIGABRT to SIG_DFL, so the arbiter’s timeout kill dumps core instead of running gunicorn’s worker_abort hook, and skips the atexit handler that shuts Galaxy down.

This worker bounds the drain, puts the SIGABRT handler back, and reports what was still in flight whenever a worker is torn down the hard way. Requests that never finish by themselves, such as event streams, can be ended when the drain starts via galaxy.web_stack.on_drain_start().

galaxy.webapps.galaxy.workers.DRAIN_REPORT_INTERVAL = 10

How often to report on a drain that is still in progress.

galaxy.webapps.galaxy.workers.DRAIN_POLL_INTERVAL = 0.25

How often the drain reporter wakes up.

galaxy.webapps.galaxy.workers.DRAIN_DEADLINE_LEAD = 1.0

How far ahead of uvicorn’s own cancellation to report the requests it will cancel.

galaxy.webapps.galaxy.workers.STACK_FRAME_LIMIT = 30

Frames to keep per thread in the stack dump.

class galaxy.webapps.galaxy.workers.Worker(*args: Any, **kwargs: Any)[source]

Bases: UvicornWorker

Galaxy’s gunicorn worker. Referenced by name in gravity and startup scripts.

__init__(*args: Any, **kwargs: Any) → None[source]

This is called pre-fork so it shouldn’t do anything to the current process. If there’s a need to make process wide changes you’ll want to do that in self.init_process().

init_signals() → None[source]
async report_drain(server: Server) → None[source]

Log what is holding a graceful shutdown open, while it is still open.

in_flight_summary() → str[source]

Compact description of what this worker is still serving.

Kept small enough to survive as a Sentry event message. Called from a signal handler on the abort path, so it must never raise.

in_flight_stacks() → str[source]

Full stacks for the request tasks and every thread.

The thread pass is the important one: Galaxy’s sync and legacy WSGI endpoints run in a threadpool, so a request task stack usually bottoms out at run_in_threadpool and the code that is actually stuck is only visible here.