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?
Asked
Active
Viewed 206 times
1 Answers
2
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.

shx2
- 61,779
- 13
- 130
- 153
-
Thanks, I am not quite ready to implement this but it is coming shortly. I'll test it out but the solution looks very promising indeed. – Gregory Kuhn Jan 18 '16 at 23:19