Skip to content
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

How to cancel all the pending requests at the server? #542

Open
XanthanGumm opened this issue Aug 30, 2023 · 0 comments
Open

How to cancel all the pending requests at the server? #542

XanthanGumm opened this issue Aug 30, 2023 · 0 comments

Comments

@XanthanGumm
Copy link

Describe the issue briefly here, including:

Noob question,
In the below example there is no sense. This is just an example which the server holds a queue of pending requests.
How to cancel all pending requests at the server?

Thank you in advance,

Environment
  • rpyc latest
  • python 3.11
  • operating Windows
Minimal example

Server:

import rpyc
import random
import time
from rpyc.utils.server import OneShotServer


class RandomNumber(rpyc.Service):
    def gimme_number(self):
        number = random.rantint(1, 10)
        time.sleep(random.randint(1, 5))
        return return number


if __name__ == "__main__":
    rpyc.lib.setup_logger()
    server = OneShotServer(HelloService, port=12345)
    server.start()

Client:

import rpyc

def on_request_arrival(req):
     if req.value == 5:
          # cancel all the requests at the server's queue.


if __name__ == "__main__":
    c = rpyc.connect("localhost", 12345)
    f = rpyc.async_(c.root.gimmie_number)
    reqs = []
    for i in range(25):
         req = f()
        req.add_callback(on_request_arrival)
        reqs.append(req)

     while not all(r.ready for r in reqs):
          pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant