Message361841
Андрей,
Here's how you can fix your example:
import asyncio
class Singleton:
_LOCK = None
_LOOP = None
@classmethod
async def create(cls):
if cls._LOOP is None:
cls._LOOP = asyncio.get_running_loop()
cls._LOCK = asyncio.Lock()
loop = cls._LOOP
if loop is not asyncio.get_running_loop():
raise RuntimeError()
if not hasattr(cls, '_Singleton__instance'):
async with cls._LOCK:
if not hasattr(cls, '_Singleton__instance'):
await asyncio.sleep(1)
cls.__instance = cls()
return cls.__instance |
|
Date |
User |
Action |
Args |
2020-02-12 00:05:07 | yselivanov | set | recipients:
+ yselivanov, asvetlov, cjrh, heckad |
2020-02-12 00:05:07 | yselivanov | set | messageid: <1581465907.11.0.0885918685453.issue39483@roundup.psfhosted.org> |
2020-02-12 00:05:07 | yselivanov | link | issue39483 messages |
2020-02-12 00:05:07 | yselivanov | create | |
|