Writing a multithreaded, multicall XML-RPC server
You can make your XML-RPC server accept multiple calls simultaneously. This means that multiple function calls can return a single result. In addition to this, if your server is multithreaded, then you can execute more code after the server is launched in a single thread. The program's main thread will not be blocked in this manner.
How to do it...
We can create a ServerThread
class inheriting from the threading. Thread class and wrap a SimpleXMLRPCServer
instance in an attribute of this class. This can be set up to accept multiple calls.
Then, we can create two functions: one launches the multithreaded, multicall XML-RPC server, and the other creates a client to that server.
Listing 7.2 gives the code for writing a multithreaded, multicall XML-RPC server, as shown:
#!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 7 # This program is optimized for Python 3.5.2. # To make it work with Python 2.7.12: ...