Skip to content

Instantly share code, notes, and snippets.

@agcom
Created July 15, 2025 03:37
Show Gist options
  • Save agcom/b239f583ea18ca21c86627dba8aecfe9 to your computer and use it in GitHub Desktop.
Save agcom/b239f583ea18ca21c86627dba8aecfe9 to your computer and use it in GitHub Desktop.
Python Simple AsyncIO Object Initialization
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