How to use web.background

WARNING web.backgrounder was moved to experimental with web.py 3.x and it no longer part of the default distribution. You can get it from here and put it in the same directory as application.py i.e. the web directory for this to work.

Intro

web.background (and web.backgrounder) are python function decorators which allow you to execute a function in a separate background thread to that thread which served the current HTTP request and later report back on the status of the background thread (the stdout of the background function is in effect returned to the "backgrounder" that initiated the thread.

This allows you to respond quickly to the client and move to to serving other http requests, while the background thread performs some long running function.

On requesting http://localhost:8080/ you will be redirected automatically to a URL like http://localhost:8080/?_t=3080772748 ( depending on the background thread id) and (after you hit refresh a few times) you'll see something like;