I want to create and store a singleton object such that, the variable necessarily has different object for different event loops (running concurrently) and for a single event loop, all coroutines executing inside the eventloop shares the same object.
(what i want is contextVars which operate at the event loop scope. cannot use contextVars as coroutines have different contexts and hence different objects.)
I do not control creation of event loops. I only have access to a coroutine (async def func()) executing inside an eventloop.
Usecase: I am running a django server on gunicorn with uvicorn worker (afaik, different requests can run concurrently on the same worker at any time, but with differnet event loops). I want to share a connection pool, and the connection pool implementation binds itself to an eventloop (usage of asyncio lock, condition and queue) ), making global-variable like singleton erroneous.
There are some other hacky solutions, like attaching the singleton to the request object, or attaching the singleton to the current event loop object, but the requirement seems like a fundamental usecase, and hopefully python has thought about it and solved the same.