async/await
の構文を使用した後に、プログラムが正しく機能しなくなっています。しかし例外はありません。たとえば :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
しかし、私はtry/except
構文の例外を使用する場合catchedすることができます。
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')
Soがキャッチせずにすぐに例外を見ることはできますか?あるいは、私はステップを使用してすべてをデバッグできますか?
環境変数PYTHONASYNCIODEBUG = 1を設定して起動します。 – wim
@wimは役に立ちません(エラーは表示されません)。しかし、コンソール(エラーではない)で多くのデバッグ・トレースバックが表示されるようになりました。 – Broly
文書によれば、それは助けなければならない。 https://docs.python.org/3/library/asyncio-dev.html#detect-exceptions-never-consumed – Petr