I have a Flask application where I initialize a connection to a device upon server startup. In other words, I initialize this connection in the same file as I call app.run
. This connection comes in the form of an object that calls functions on this device, using the established connection. I want this connection to persist throughout the lifetime of the server, and I would ideally like this object to persist throughout the lifetime of the server. Since Flask could potentially start multiple threads to handle requests to the server.
Where and how is the best way to initialize such an object such that it's
initialized exactly once
able to be accessed in multiple
Blueprint
s
Perhaps I'm looking for something like a Singleton?
Thanks!