-
Notifications
You must be signed in to change notification settings - Fork 81
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
fix: async streaming handler send to queue logic #162
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
olbychos
approved these changes
Feb 25, 2025
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.
👍 Looks good to me! Reviewed everything up to 6da2821 in 1 minute and 18 seconds
More details
- Looked at
60
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
8
drafted comments based on config settings.
1. dynamiq/callbacks/streaming.py:62
- Draft comment:
Nice abstraction: using send_to_queue instead of directly calling put_nowait centralizes the queue logic. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
2. dynamiq/callbacks/streaming.py:83
- Draft comment:
Consistent refactoring: using send_to_queue for workflow end event as well. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
3. dynamiq/callbacks/streaming.py:95
- Draft comment:
The new send_to_queue method in the base handler encapsulates queue logic well. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
4. dynamiq/callbacks/streaming.py:178
- Draft comment:
Using asyncio.run_coroutine_threadsafe for queue.put is appropriate for thread-safe calls; consider checking or handling the returned Future for potential exceptions. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
5. dynamiq/callbacks/streaming.py:176
- Draft comment:
Consider potential deprecation of asyncio.get_event_loop; using asyncio.get_running_loop() might be preferable if the context allows. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
6. dynamiq/callbacks/streaming.py:64
- Draft comment:
Refactored to use send_to_queue(event) improves maintainability by centralizing event dispatch logic. Ensure all overrides maintain consistent behavior. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
7. dynamiq/callbacks/streaming.py:179
- Draft comment:
Using asyncio.run_coroutine_threadsafe in send_to_queue requires the event loop to be running in a separate thread. Consider checking the returned Future for exceptions to handle potential errors. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50%
The comment makes a valid technical point - run_coroutine_threadsafe returns a Future that could contain exceptions that should be handled. However, the base class already has error handling in _iter_queue_events. The comment also assumes threading usage that may not be accurate - the loop could be in the same thread. The suggestion is somewhat speculative without knowing the full threading context.
I may be overlooking a critical error case that could be missed by the existing error handling. The threading assumptions could be correct in ways not visible in this file.
While valid points, keeping error handling at the iteration level rather than queue insertion level is a reasonable design choice. Without stronger evidence that this is definitely an issue, the comment remains somewhat speculative.
The comment should be removed as it makes assumptions about threading and suggests error handling changes without clear evidence that the current approach is problematic.
8. dynamiq/callbacks/streaming.py:173
- Draft comment:
Consider using asyncio.get_running_loop() instead of asyncio.get_event_loop() for retrieving the loop, to ensure a valid running loop in modern Python async contexts. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50%
get_running_loop() is indeed preferred in modern Python as it ensures there's an active loop, while get_event_loop() may create new loops leading to issues. However, this class appears to be designed to work across threads (given run_coroutine_threadsafe usage), where get_running_loop() could fail if called from a different thread. The current implementation is likely intentional for cross-thread compatibility.
I might be wrong about the cross-thread usage intention. Maybe the class is always used within the same event loop context.
The use of run_coroutine_threadsafe strongly suggests this is designed for cross-thread scenarios, where get_event_loop() is actually the correct choice.
The current implementation using get_event_loop() appears to be correct for this use case. The comment should be deleted as it could lead to incorrect changes.
Workflow ID: wflow_Twr2khEx1t2rmmEM
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
MaksymAI
approved these changes
Feb 25, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Refactor queue handling in
StreamingQueueCallbackHandler
by introducingsend_to_queue
method, with async handling inAsyncStreamingIteratorCallbackHandler
.send_to_queue
method inStreamingQueueCallbackHandler
to encapsulate queue sending logic.send_to_queue
inAsyncStreamingIteratorCallbackHandler
to useasyncio.run_coroutine_threadsafe
for async queue operations.self.queue.put_nowait(event)
withself.send_to_queue(event)
inon_node_execute_stream
andon_workflow_end
methods ofStreamingQueueCallbackHandler
.This description was created by
for 6da2821. It will automatically update as commits are pushed.