250x250
반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

BEAT A SHOTGUN

[TROUBLESHOOTING] Runtimewarning: coroutine was never awaited 본문

TROUBLESHOOTING

[TROUBLESHOOTING] Runtimewarning: coroutine was never awaited

thovy 2023. 2. 2. 23:32
728x90
반응형
SMALL

코루틴이 기다리지 않습니다.

당황스럽게도 메서드가 실행되지 않았다.
상황은 이렇다.

ERROR ❌

과거의 나와 당신은 분명

def run(self):
    return asyncio.run(self.firstfunc())

이런 함수를 만들어놓고

async def coroutinemethod():
    print("wait a moment")

async def firstfunc(self):
    self.coroutinemethod()
    print("first funct)

이지랄해놓았을거다

Solution ✅

과거의 나와 당신은 분명 '아늬 함수를 호출했는데 왜? 뭘 안 기다린다는겨' 라고 했을 거지만,
코루틴 함수는 호출하면 함수를 실행하는 게 아니라 코루틴 객체를 생성한다.

firstfunc 메서드를

def firstfunc(self):
    ❌ self.coroutinemethod()

def firstfunc(self):
    ✅ temp = self.croutinemethod()

이렇게 하면 temp 객체를 사용하지 않더라도 일단 coroutinemethod 가 실행이 된다.

추가로 혼나기

물론 위의 솔루션은 맨 처음 실행하는 run 메서드를 asyncio 로 실행했을 때의 이야기다.
'아늬 객체 받아줬는데도 안 되는데요' 하면 미래의 자신에게 호되게 혼나야됨. 난 안 혼남✌
asyncio 로 실행하지 않은 거다.

난 한 번만 혼나서 매우 기분 좋음.

댕청해지지 않도록 항상 조심하자!

오랜만!

참고
https://superfastpython.com/asyncio-coroutine-was-never-awaited/

728x90
반응형
LIST
Comments