Search code examples
pythonxml-rpcrpcxmlrpclibxmlrpcclient

Cancel xmlrpc client request?


Is it possible to somehow cancel xmlrpc client request?

Let say that in one thread I have code like:

svr = xmlrpclib.ServerProxy('http://localhost:9092')
svr.DoSomethingWhichNeedTime()

I don't mean some kind of TimeOut... Sometimes from another thread I can get event to cancel my work. And then I need to cancel this request.

I know that I can do it with twisted but, is it possible to do it with standard xmlrpclib?


Solution

  • First of all, it must be implemented on server side, not in client (xmlrpclib). If you simply interrupt your HTTP request to XML-RPC server, it's not guaranteed that long process running on the server will be interrupted at all. So xmlrpclib just can't have this functionality.

    If you want to implement this behaviour, you need to create two type of requests. A request of first type will tell your server to start some long process. It must be executed in background (in another thread or process), and your XML-RPC server must send the response ("Process started!") to the client immediately. When you want to stop the process, client must send another request that will tell your server to stop executing of process.