Here is an example of a complete app:
This function does the computation, here it just sleeps for 5 secs
def background():
import time
time.sleep(5)
return "computation result" # this could an image, HTML, JSON, etc...
This is the page accessed by the user. The computation is called by an ajax call and executed in background.
def foreground():
return dict(somescript=SCRIPT("ajax('background',[],'target');"),
somediv=DIV('working...',_id='target'))