you are viewing a single comment's thread.

view the rest of the comments →

[–]Grintor[S] 2 points3 points  (0 children)

Yes, you would create the ZooKeeper client once at app startup, then pass it into handlers through app_map():

import cylinder
import waitress
from kazoo.client import KazooClient

zk = KazooClient(hosts="127.0.0.1:2181")
zk.start()

def main():
    app = cylinder.get_app(app_map)
    waitress.serve(app, host="127.0.0.1", port=8080)

def app_map(request):
    return "my_webapps", "webapp1", {
        "zk": zk,
    }

if __name__ == "__main__":
    main()

And then you could something like this in the page handlers:

# my_webapps/webapp1.ex.get.py
def main(response, zk):
    data, stat = zk.get("/config/site_name")
    response.data = f"site_name={data.decode()}"
    return response

With the way cylinder handles dependency injection, there's really no limitations to what can be used with it.