Hello, what is the best way to use global variable...
# ask-community
z
Hello, what is the best way to use global variables, for example database engine objects, in different tasks?
z
Hi Zach -- is your database engine object serializable or is it holding a connection?
z
Hi Michael, it’s a postgres connection created with sqlalchemy create_engine, I don’t think it’s serializable
z
There isn't a robust pattern for this yet as it's a bit tricky once you're in a distributed setting. There's a bit of WIP that's out of date now (https://github.com/PrefectHQ/prefect/pull/3139) to create a util for this, but for now you're stuck creating the connection in each task. The definition for it can be stored in a global variable but it'll need to be instantiated in each task.