☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Lifecycle Hooks

Community Support
alexgrossman
alexgrossman

How do I use lifecycle hooks within a Flask app?

When using them, how I refer to them within the document (bkapp(doc))?
i.e. how do I save things to a ‘BokehServerContext’ object? How do i then reference this within the main.py file?

⌁   Link to post
Bryan
Bryan

You can use lifecycle hooks in a Flask context, but it is an advanced and uncommon thing to do, and does not have all the conveniences that the “directory format” bokeh server apps with an app_hooks.py file has. You will have to create an actual handler class to configure on the application:

from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.application.handlers.lifecycle import LifecycleHandler
class MyHandler(LifecycleHandler):
    def on_server_loaded(self, server_context):
        print("SERVER LOADED")
bkapp = Application(FunctionHandler(bkapp), MyHandler())
⌁   Link to post

End of archived discussion · Replies are disabled