Bottle Plugin Lifecycle

If you use Python‘s Bottle micro-framework there’ll be a time where you’ll want to add custom plugins. To get a better feeling on what code gets executed when, I created a minimal Bottle app with a test plugin that logs what code gets executed. I uesed it to test both global and route-specific plugins.

When Python loads the module you’ll see that the plugins’

__init__()

and

setup()

methods will be called immediately when they are installed on the app or applied to the route. This happens in the order they appear in the code. Then the app is started.

The first time a route is called Bottle executes the plugins’

apply()

methods. This happens in “reversed order” of installation (which makes sense for a nested callback chain). This means first the route-specific plugins get applied then the global ones. Their result is cached, i.e. only the inner/wrapped function is executed from here on out.

Then for every request the

apply()

method’s inner function is executed. This happens in the “original” order again.

Below you can see the code and example logs for two requests. You can also clone the Gist and do your own experiments.

https://twitter.com/riyadpr/status/617681143538786304

White Space As Unused Advertising Space

has a few points on why it’s stupid to think of all white space as unused advertising space.

[Look,] here is an “inefficient” use of space that could instead be used to “inform” the public of “opportunities.”

It’s interesting to see how one of the most wasteful industries of our society claims to make things more efficient by wasting people’s time and cluttering up everything.

Übergewicht senkt Demenzrisiko

Ein weiter Beweis dafür, dass der Verein zur Pflege des Wohlstandsbauches einen wichtigen Beitrag zur Volksgesundheit leistet. Wissenschaftler haben die Gesundheitsdaten von fast 2 Mio. Briten über 20 Jahre ausgewertet und kommen zum Ergebnis, dass Übergewicht das Demenzrisiko senkt.