This page explains some of inner workings of TurboGears. This may be interesting to users wanting to extend TurboGears or for prospective core TG developers. While we try to be as accurate as we can and as detailed as necessary, the definite reference is always the source!
What happens when you start a TurboGears application until it is ready to process requests? How are the bits and pieces that make up the TurboGears framework assembled together? Please read the following section to learn more than you probably wanted to know!
Somebody (you, an init script, supervisor, mod_wsgi) runs the application’s start script. It simply imports the start function from the command module of the app and runs it.
The start function looks for a deployment configuration file in several places (see comments in command.py) and loads it, as well as the configuration from the config/*.cfg files in your app’s package. Parsing the configuration also triggers setting up the logging handlers etc.
When the startup module is imported, it replaces the CherryPy auto-reloader with TurboGears’ own implementation.
start_server mounts the root controller to the CherryPy object tree and starts the CherryPy server.
This triggers calling the turbogears.startup. startTurboGears function, because it is listed in the on_start_server_list attribute of the CherryPy server. This function handles the remaining initialization tasks (in given order):
Turns off CherryPy’s debug logging filter (which CherryPy normally turns on by default in development mode).
Adds a static filter for TurboGears’s static files (URL "/tg_static").
Adds the CherryPy decoding filter to the root URL ("/") if enabled in the configuration.
Loads the template engines and the base templates.
Adds the following CherryPy request filters to the root controller:
When in development mode, registers the server with the Bonjour framework, if available.
Calls turbogears.database. bind_metadata when using SQLAlchemy.
Loads all turbogears.extensions entry points and calls their start_extension method. The standard extensions included with TurboGears are:
Calls the callables registered in turbogears.call_on_startup.
Starts the TurboGears scheduler if enabled.