Open sersorrel opened 1 month ago
Hi thanks for reaching out :)
Reading the docs , or the code (e.g. definition of .other, definition of call
, definition of async_call) will show you that .other
and call
are synchronous while async_call is async.
You'd probably have better results using channel.async_call()
and gathering on the wait function of the promises.
Thanks for the pointers. Looking more closely, I'm not actually sure I can achieve the behaviour I want as it stands, since WebsocketRPCEndpoint
fundamentally waits for each call to complete before it starts listening for the next call:
I suppose I could use a callback style, like call_me_back
does:
but that leaks the result of create_task
, which means the async_call
task could be garbage-collected at any moment, and anyway if I wanted to handle the callbacks myself I could just run a regular HTTP server on both ends and requests.get()
between them :)
I will think about ways to improve this.
fundamentally waits for each call to complete before it starts listening for the next call
If your rpc_method being called is async (meaning spins off a task to do it's work) then that's a none-issue.
but that leaks the result of create_task
That's just a testing utility method Use async_call directly and save the created task (for example in a class member -this would work very well with a context manager class you can have for your service).
Say you have the following handler:
I adapted the
test_recursive_rpc_calls
test to see what would happen if I called this several times simultaneously (usingasyncio.create_task
to schedule all the calls for execution at once, rather than waiting for them to complete in order). I expected that while the handler isasyncio.sleep
ing, other handlers would be free to run, so regardless of how many times I call the handler, it shouldn't take much more than a second to complete (since that's the behaviour I would see if I were calling it like a regular async function, rather than via the RPC protocol):However, this test fails:
Rather than running simultaneously, the handlers are running one after the other – so the test takes five full seconds to complete...
Is it expected behaviour that only one RPC handler can be executing at any given time?