때로는 async/await
구문을 사용한 후에 프로그램이 더 이상 제대로 작동하지 않습니다. 그러나 예외는 없습니다. 예를 들어 : 나는 try/except
구문 예외를 사용하는 경우asnycio의 예외가 늦거나 전혀 나타나지 않는 이유는 무엇입니까?
async def my_func(self):
async with self.engine() as conn:
print('step1') # step1 shows in console
await conn.exceute("INSERT INTO bla-bla")
print('step2') # I can't watch 'step2', and no any exceptions caughted to console
는 그러나 사로 잡았 할 수 있습니다
async def my_func(self):
async with self.engine() as conn:
print('step1') # step1 shows in console
try:
await conn.exceute("INSERT INTO bla-bla")
except Exception as e:
print_exc() # only by this way I can see whats wrong
print('step2')
겠어요 - 잡기없이 즉시 예외를 볼 수 있습니까? 아니면 단계 만 사용하고 모두 디버깅 할 수 있습니까?
환경 변수 PYTHONASYNCIODEBUG = 1을 설정하여 시작하십시오. – wim
@wim은 도움이되지 않습니다 (오류는 계속 표시되지 않음). 하지만 이제는 콘솔에서 많은 디버그 추적을보고 (오류가 아닌), 눈을 부시게됩니다. – Broly
설명서에 따르면, 도움이됩니다. https://docs.python.org/3/library/asyncio-dev.html#detect-exceptions-never-consumed – Petr