Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python RPyC user count

Tags:

python

rpyc

I wish to use RPyC to provide an API for a hardware board as a service. The board can only cater for a single user at a time. Is there any way I can get RPyC to enforce that only a single user can get access at a time?

like image 566
Gregory Kuhn Avatar asked Oct 30 '22 11:10

Gregory Kuhn


1 Answers

I'm not sure if this would work (or work well), but you can try starting a OneShotServer inside a loop, thus at any given moment only one connection is served. When the connection is closed, the server terminates, and you start another one for the next client.

Something like:

is_aborting = False
while not is_aborting:
    server = OneShotServer(myservice, *args, **kwargs)
    # serve the next client:
    server.start()
    # done serving the client

If this doesn't work, your best bet is to subclass ThreadedServer, and override the _accept_method method to keep track if there's already a connection open, and return an error if there is.

like image 63
shx2 Avatar answered Nov 15 '22 05:11

shx2