Persistent database connections in module level variables

Hi,

I have a python module that is connecting to a Sql Server database using Sqlalchemy.

The sqlalchemy engine is define as module level variable. Another helper class is also instantiated as
a module level variable. From my Zato services I am importing these variables

My suspicion is that this is not the right approach, because it seems that sometimes these variables get gargage collected.

Zato services cannot hold state. So my question is, what is the correct approach to do one-time initializations in python modules that are used by Zato services.

Regards, Jan

So my question is, what is the correct approach to do one-time initializations in python modules that are used by Zato services.

I don’t have an immediate answer but can you try wrapping this initialization code in a gevent.lock.RLock() lock?