Can't catch exception raised during execution of an asyncio.Task
if running with --opt
#387
Labels
wontfix
This will not be worked on
773f99790e66b4865529da353a270052b7020a42
I've managed to reproduce this on Ubuntu with Python 3.10 and an older Granian version as well, so not sure if the above version info is really relevant, just included for good measure.
The issue is that with
--opt
, if you run and await a coroutine withasyncio.create_task()
, any exceptions raised in the task can't be caught from the outside.Repro case
repro.py
:When running the app without
--opt
, we get the expected response:But the same request with
--opt
enabled results in this:And the custom error response is not returned:
While writing this issue, I noticed that if I move the whole
try ... except
block inside the function that's wrapped in a task everything works as expected, so this seems to be less of an issue than I originally thought.Anyway, this issue seems somewhat related to #323, so if you still feel like just dropping
--opt
in the future feel free to close this aswontfix
😅The text was updated successfully, but these errors were encountered: