-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Allow callback handlers to opt into being run inline #6424
Conversation
This is useful eg for callback handlers that use context vars (like open telemetry)
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -259,12 +262,17 @@ async def _ahandle_event( | |||
**kwargs: Any, | |||
) -> None: | |||
"""Generic event handler for AsyncCallbackManager.""" | |||
for handler in [h for h in handlers if h.run_inline]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that the same as
_handle_event(sync_handlers)
And then we don't have to handle that case in _ahandle_event_for_handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no because there is other logic in there that I do want to still apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the logic exactly the same in these two functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then we'd be repeating here the check for whether an event handler is sync or async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we put the check here and call _handle_event on sync handlers, we don't need to change the _ahandle... function at all.
Sync handlers will never get there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Is that something that should be supported or it's considered as misconfiguration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it won't have any effect, as the concept doesn't make sense. But not sure its worth throwing an exception for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at the current implementation and see that we're not awaiting if run_inline
is true. What will happen if we run async function with run_inline
and don't await on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, makes total sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for handling this case.
This is useful eg for callback handlers that use context vars (like open telemetry)
See #6095