[feat] Improve TransferQueueClient sync API compatibility with async contexts#11
Merged
ji-huazhong merged 6 commits intoAscend:mainfrom Jan 26, 2026
Merged
[feat] Improve TransferQueueClient sync API compatibility with async contexts#11ji-huazhong merged 6 commits intoAscend:mainfrom
TransferQueueClient sync API compatibility with async contexts#11ji-huazhong merged 6 commits intoAscend:mainfrom
Conversation
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the synchronous TransferQueueClient API so it can safely be used from environments where an asyncio event loop is already running (e.g., Jupyter), by switching from asyncio.run() to asgiref’s async_to_sync. It also adds asgiref as an explicit dependency.
Changes:
- Replace direct
asyncio.run()calls inTransferQueueClientsync methods with instance-bound wrappers generated viaasgiref.sync.async_to_sync. - Introduce a private
_bind_sync_methodshelper invoked inTransferQueueClient.__init__to bind all sync wrappers in one place. - Add
asgireftorequirements.txtand remove the unusedasyncioimport fromtransfer_queue/client.py.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
transfer_queue/client.py |
Refactors sync TransferQueueClient methods to use async_to_sync wrappers instead of asyncio.run, centralizing wrapper creation in _bind_sync_methods. |
requirements.txt |
Adds the asgiref dependency required for the new async-to-sync bridge. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
TransferQueueClient sync API compatibility with async contextsTransferQueueClient sync API compatibility with async contexts
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
Signed-off-by: 0oshowero0 <o0shower0o@outlook.com>
TransferQueueClient sync API compatibility with async contextsTransferQueueClient sync API compatibility with async contexts
ji-huazhong
approved these changes
Jan 26, 2026
This file contains hidden or 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
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.
Background
The existing sync APIs in
TransferQueueClientare implemented by wrapping the original async methods inAsyncTransferQueueClientwithasyncio.run().This works when the caller is in a purely synchronous context. However, in environments where an event loop is already running (for example, Jupyter Notebook), calling these sync APIs will fail unless users manually switch to the async APIs.
Solution
This PR replaces the direct use of
asyncio.run()by creating a dedicate event loop in a new thread.This allows the sync APIs in
TransferQueueClientto work reliably in both synchronous and asynchronous environments without requiring changes from the user.TODO
TransferQueueClientsince it supports both sync & async APIs.CC: @vermouth1992 @wuxibin89