문제
코루틴에서 asyncio.ensure_future
을 사용할 때 자세한 함수 추적 정보가 표시되지 않습니다.
해결책
ensure_future
에서 생성된 선물은 생성된 동일한 코루틴에서 대기해야 합니다. 예를 들어, 이전 섹션에서 await
은 ensure_future
와 함께 존재하지 않으므로 정보가 누락됩니다.
이전 :
import asyncio
async def foo(): ensure_future(bar())
async def bar(): await asyncio.sleep(0.5)
이후 :
import asyncio
async def foo(): await ensure_future(bar())
async def bar(): await asyncio.sleep(0.5)