tomerfiliba-org/rpyc

How to poll an AsyncResult without blocking?

patrickkidd opened this issue · 3 comments

Describe the issue briefly here, including:

  • Expected result: Should be able to access AsyncResult.ready without blocking until remote call has completed.
  • Actual result: if async_result.ready: blocks until remote call has completed. I am unable to find the code containing the blocking call. The AsyncResult.ready implementation shows no blocking calls, yet stepping into that method from my code somehow blocks before entering it.

Steps to reproduce:

asleep = rpyc.async_(conn.modules.time.sleep)
result = asleep(5)
assert result.ready == False # This assertion fails because it blocks until the sleep completes 5 seconds after the previous line.
Environment
  • rpyc version: 5.3.0
  • python version: 3.9.13
  • operating system: Linux/Ubuntu
Minimal example

See above

Is it only possible to execute a single async call at a time? Maybe is this limited by the single python thread on the remote side? The use case here is to be able to run multiple remote method calls in parallel, ideally using the same objects. So I suppose threads.

The only way I could figure out a truly multi-call async solution to this was to:

  • Create a threaded N-workers pool model on the server side, and a rpyc.BgServingThread
  • Pass a client-side callback to each call to the server and return a custom promise type.
  • Wrap the client's callback with rpyc.async_(...) on the server before calling it
  • Mark the promise completed and raise any remote exceptions in the promise's handler.

I'm still writing custom code for every server function call but I don't know how else to do it.

Same here, I ended up batching the calls, seemed simpler. Can somebody with insight explain the limitation?