Created
July 15, 2025 03:37
-
-
Save agcom/b239f583ea18ca21c86627dba8aecfe9 to your computer and use it in GitHub Desktop.
Python Simple AsyncIO Object Initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
class Test: | |
def __init__(self) -> None: | |
print("__init__") | |
async def __ainit__(self) -> None: | |
print("__ainit__") | |
def __await__(self): | |
async def _coro(): | |
await self.__ainit__() | |
return self | |
return _coro().__await__() | |
async def amain(): | |
t = await Test() | |
asyncio.run(amain()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment