Message381370
Yeah, I follow the reasoning.
My use case:
class Something:
def __init__(self):
self._lock = asyncio.Lock()
async def do_something():
async with self._lock:
...
And `Something` won't be created in a coroutine. So now I have to jump through the hoops to implement lazy lock instantiation.
> But the lock is tightly coupled with a loop instance. In other words, the loop belongs to the loop.
>The lock cannot be used after the loop dies (stopped and closed).
I agree. Maybe the solution should be this then:
class asyncio.Lock:
def _get_loop(self):
loop = asyncio.get_running_loop()
if self._loop is None:
self._loop = loop
if loop is not self._loop: raise
if not loop.is_running(): raise
async def acquire(self):
loop = self._get_loop()
...
This is what would guarantee all protections you want and would also allow to instantiate `asyncio.Lock` in class constructors, simplifying code. |
|
Date |
User |
Action |
Args |
2020-11-18 19:20:35 | yselivanov | set | recipients:
+ yselivanov, asvetlov, aeros |
2020-11-18 19:20:35 | yselivanov | set | messageid: <1605727235.09.0.614556228567.issue42392@roundup.psfhosted.org> |
2020-11-18 19:20:35 | yselivanov | link | issue42392 messages |
2020-11-18 19:20:34 | yselivanov | create | |
|