mirror of
https://github.com/koush/scrypted.git
synced 2026-02-03 06:03:27 +00:00
server: python rpc should use create_task instead of run_coroutine_threadsafe (#1953)
run_coroutine_threadsafe is designed for scheduling coroutines from a different thread onto the event loop. Since readLoop is already running as an async function on the event loop, using create_task is the correct and more efficient approach. This removes unnecessary thread-safe queue overhead for every RPC message. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -206,7 +206,7 @@ class RpcConnectionTransport(RpcTransport):
|
||||
return self.writeMessage(bytes(buffer), reject)
|
||||
|
||||
|
||||
async def readLoop(loop, peer: rpc.RpcPeer, rpcTransport: RpcTransport):
|
||||
async def readLoop(peer: rpc.RpcPeer, rpcTransport: RpcTransport):
|
||||
deserializationContext = {"buffers": []}
|
||||
|
||||
while True:
|
||||
@@ -216,9 +216,7 @@ async def readLoop(loop, peer: rpc.RpcPeer, rpcTransport: RpcTransport):
|
||||
deserializationContext["buffers"].append(message)
|
||||
continue
|
||||
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
peer.handleMessage(message, deserializationContext), loop
|
||||
)
|
||||
asyncio.create_task(peer.handleMessage(message, deserializationContext))
|
||||
|
||||
deserializationContext = {"buffers": []}
|
||||
|
||||
@@ -246,7 +244,7 @@ async def prepare_peer_readloop(loop: AbstractEventLoop, rpcTransport: RpcTransp
|
||||
|
||||
async def peerReadLoop():
|
||||
try:
|
||||
await readLoop(loop, peer, rpcTransport)
|
||||
await readLoop(peer, rpcTransport)
|
||||
except:
|
||||
peer.kill()
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user