开发者

Python XMLRPC with concurrent requests

开发者 https://www.devze.com 2022-12-09 01:22 出处:网络
I\'m looking for a way to prevent multiple hosts from issuing simultaneous commands to a Python XMLRPC listener. The listener is responsible for running scripts to perform tasks on that system that wo

I'm looking for a way to prevent multiple hosts from issuing simultaneous commands to a Python XMLRPC listener. The listener is responsible for running scripts to perform tasks on that system that would fail if multiple users tried to issue these commands at the same time. Is there a way I can block all incoming requests until the single instance has com开发者_开发知识库pleted?


I think python SimpleXMLRPCServer module is what you want. I believe the default behavior of that model is blocking new requests when current request is processing. The default behavior gave me lots of trouble and I changed that behavior by mix in ThreadingMixIn class so that my xmlrpc server could respond multiple requests in the same time.

class RPCThreading(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
    pass

If I understand your question correctly, SimpleXMLRPCServer is the solution. Just use it directly.


Can you have another communication channel? If yes, then have a "call me back when it is my turn" protocol running between the server and the clients.

In other words, each client would register its intention to issue requests to the server and the said server would "callback" the next-up client when it is ready.


There are several choices:

  1. Use single-process-single-thread server like SimpleXMLRPCServer to process requests subsequently.
  2. Use threading.Lock() in threaded server.
  3. You some external locking mechanism (like lockfile module or GET_LOCK() function in mysql) in multiprocess server.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号