-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why define an exception handler needed async? #1804
Comments
In general all handlers in Sanic can be async or normal functions. You are free to use either even though in documentation In the current version there is a limitation that async error handlers might not work in some contexts (protocol errors), so a normal function is actually a safer choice there. This is due to be fixed in a future version. |
thx~I do meet unexcepted exception with async def in exceptions handler. And it works good with def only. |
@matianjun1 The confusion comes from the fact Sanic request handler does support async exception handlers, see here: https://github.com/huge-success/sanic/blob/60b4efad67ba3b22dfaf83820c772cd7f5ff137c/sanic/app.py#L1015-L1017 But the sanic asyncio server implementation does not support async exception handlers. So I think for now we should remove any mention of async exception handlers in the documentation, and look at how we can get async exception handlers working at the asyncio server level. |
Agreed, it would be best not to mention async exception handlers in documentation for now. This is one of the problems fixed in #1791 but it will take a few more months until that can ship, and there is no quick and easy way to fix this otherwise. |
Is is just the docs at https://sanic.readthedocs.io/en/latest/sanic/exceptions.html that show an async error handler? Are there any other mentions anywhere else that need changing? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
with tests/test_exceptions_handler.py define an exception handler like this:
but in docs https://sanic.readthedocs.io/en/latest/sanic/exceptions.html
what is the difference? And is async def needed?
The text was updated successfully, but these errors were encountered: