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())'Category > Python' 카테고리의 다른 글
| AsyncResult와 Multiprocessing.pool (0) | 2025.07.03 |
|---|---|
| Python 시간 출력 함수 총 정리 (0) | 2024.12.29 |
| Python의 with 문으로 컨텍스트 관리하기 (0) | 2024.12.08 |
| Python의 next() 함수로 이터레이터 객체 순회하기 (0) | 2024.12.08 |
| Python 소수점 자리수 제어와 숫자 포매팅 :.nf (1) | 2024.12.03 |