7

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 completed?

4
  • 1
    are the clients aware of the conflict matrix? should they be intelligent enough to schedule themselves according to this matrix? how do they activities get synchronized etc... Commented Oct 19, 2009 at 15:19
  • are you using SimpleXMLRPCServer as I thought this was single threaded... Commented Oct 19, 2009 at 16:23
  • I am using the SimpleXMLRPCServer, but it appears I can launch the same command from different hosts simultaneously, which is what i need to prevent Commented Oct 19, 2009 at 17:18
  • So on closer inspection it is executing sequentially, scheduling jobs as a first come first serve basis. With a little control logic SimpleXMLRPCServer should do exactly what I need it to, thanks all! Commented Oct 19, 2009 at 17:37

3 Answers 3

18

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I've been using SimpleXMLRPCServer for a project and am going the other way - requiring concurrent request handling, because when a request is being handled the client call fails with a CannotSendRequest exception. Just a heads up, if you don't want to require implementing retries.
0

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.

3 Comments

I'm not necessarily as concerned with calling back clients, moreso in the prevention of conflicting commands being issued by multiple hosts
can you send back an HTTP 5xx code (server busy or whatever)?
a lot of subprocess shell commands to copy files, remove files, etc.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.