Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
When Lino starts up¶
- site startup¶
The things that happen at the beginning of a Lino process.
Life cycle of a Lino process¶
Here is what happens when a Lino process wakes up.
- Lino process¶
A Python process on a given Lino site. This is either some django-admin command, or a WSGI or ASGI process inside a web server.
Step by step:
The
manage.py
script causes the module specified byDJANGO_SETTINGS_MODULE
(yoursettings.py
module) to be imported. In this phase, everything inlino.api.ad
is usable.Importing the
settings.py
module will instantiate yourSITE
.When settings are ready, Django will load the
models.py
modules. Everything inlino.api.dd
is usable during this step.lino.api.rt
may be imported but should not be accessed at global module level.When all
models.py
modules are loaded, DJango has finished to start up and Lino may finally start up. This is what we call site startup. The details of this phase are documented in The Site startup phase below.When site startup has finished, we finally enter the runtime phase. Only now everything in
lino.api.rt
is usable.
There are four major phases in the life of a Lino process:
- application definition¶
The first phase of the site startup when Django settings are being loaded. We see this as a separate phase because Lino does some magics there.
- data definition¶
The second phase of the site startup when Django models are being loaded.
- site analysis¶
The third phase of the site startup when Django models have been loaded, and Lino analyzes them to fill its own data structures.
- runtime¶
When the site startup has finished and the actual process does what it is designed to do.
There are three modules in lino.api
named after these phases:
lino.api.ad
is available during application definition.lino.api.dd
is available during data definition and site analysis.lino.api.rt
is available when site analysis has finised.
The Site startup phase¶
The application definition phase:
manage.py
setsDJANGO_SETTINGS_MODULE
and callsdjango.core.management.execute_from_command_line()
, which loads thesettings.py
file.
The Site
class gets instantiated within the settings.py
file. This instantiation does the following:
Modify Django’s
django.utils.log.DEFAULT_LOGGING
dict.Read the
lino.ini
if it exists.Call
Site.get_plugin_modifiers()
andSite.get_installed_plugins()
to build the list of plugins.Import each plugin (just the
__init__.py
of the package).Set the
INSTALLED_APPS
setting and theSite.installed_plugins
site attribute. The list of installed plugins is now known and won’t change any more.INSTALLED_APPS
is basically the same asSite.installed_plugins
, except that the former is a list of module names while the latter is a list ofPlugin
instances.Call each plugin’s
on_plugins_loaded
method.
Note that all the above-mentioned steps happen while the settings.py
is
still being loaded. This means for example that you cannot access the
settings
module in your get_plugin_configs
or on_plugins_loaded
methods.
When Django has finished loading the settings.py
file, it starts
importing the models.py
module of each plugin. We call this the
data definition phase.
When Django has fully populated its models registry (imported all
models.py
modules), it finds lino.AppConfig
and runs its
ready() method,
which does nothing more and nothing less than run Site.startup()
.
The data definition phase is done, we enter the site analysis phase. Which does the following:
Instantiate the kernel.
settings.SITE.kernel
is now an instance oflino.core.kernel.Kernel
instead of None.Fill
Site.models
, an attrdict mapping plugin app_label to their currespondingmodels.py
module.Emit the
lino.core.signals.pre_startup
signalRun
pre_site_startup
of each pluginRun
Kernel.kernel_startup()
, which does:Register
Site.shutdown()
toatexit
and stop signal handler.Install a
DisableDeleteHandler
for each model intoModel._lino_ddh
.Install
lino.core.model.Model
attributes and methods into raw Django Models that don’t inherit from it.Populate
Site.GFK_LIST
, a list of all generic foreign key fields in the database.Import
Site.user_types_module
Analyze ForeignKeys and populate the
DisableDeleteHandler
.Import
Site.workflows_module
Run
lino.core.plugins.Plugin.before_analyze()
on each pluginEmit the
lino.core.signals.pre_analyze
signalImport
Site.custom_layouts_module
if defined.Call
lino.core.model.Model.on_analyze()
on every model.Call
lino.core.model.Model.collect_virtual_fields()
on every model. This attaches virtual fields to the model that declares them.Run
lino.core.plugins.Plugin.before_actors_discover()
on each plugin.Discover and initialize actors
Emit the
lino.core.signals.post_analyze
signalRun
lino.core.actors.Actor.after_site_setup()
on each actorEmit the
lino.core.signals.pre_ui_build
signalRun
lino.core.plugins.Plugin.on_ui_init()
on each plugin
Run
lino.core.plugins.Plugin.post_site_startup()
on each pluginEmit the
lino.core.signals.post_startup
signal