I have module serv.py:
async def init_serv():
serv = Serv()
return await serv.init_with_params()
(of course, this is an abbreviated version)
In other modules I am doing:
from serv import init_serv
serv = init_serv()
This works fine, but whenever I import this module it creates a new instance of it.
I would like to have one instance, so if it wasn't asynchronous I could do that:
serv.py:
async def init_serv():
serv = Serv()
return await serv.init_with_params()
serv = init_serv()
and in other modules:
from serv import serv
But this obviously doesn't work because I'm calling an asynchronous function outside the async function.
What is the best solution for this?