본문 바로가기
Category/Python

[Python] asyncio example

by Corinee 2025. 6. 12.
728x90
반응형
import asyncio

queue = asyncio.Queue()

async def producer():
    for i in range(3):
        await queue.put(f"update {i}")
        await asyncio.sleep(1)  # 1초마다 상태 변경

async def consumer():
    while True:
        data = await queue.get()
        print("SSE Send:", data)
        if data == "update 2":
            break

async def main():
    await asyncio.gather(producer(), consumer())

asyncio.run(main())