Question

Basicly I want to run my xmlrpc server in separate thread or together with my other code, however, after server.serve_forever() there's no way that I can get my another code running after this function. seem server.serve_forever() is running forever there.

self.LocalServer = SimpleThreadedXMLRPCServer(("localhost",10007))
self.LocalServer.register_function(getTextA) #just return a string
self.LocalServer.serve_forever()
print "I want to continue my code after this..."
.... another code after this should running together with the server

I tried the multithreading concept but still no luck here. Basicaly I want to run the xmlrpc server together with the rest of my code.

Thank you for your kind of help.

Was it helpful?

Solution

You could create a ServerThread class to encapsulate your XML-RPC server and run it in a thread :

class ServerThread(threading.Thread):
    def __init__(self):
         threading.Thread.__init__(self)
         self.localServer = SimpleThreadedXMLRPCServer(("localhost",10007))
         self.localServer.register_function(getTextA) #just return a string

    def run(self):
         self.localServer.serve_forever()

You can use this class the following way :

server = ServerThread()
server.start() # The server is now running
print "I want to continue my code after this..."

OTHER TIPS

I wanted to do the same thing as you and this is how I do it.

server = SimpleXMLRPCServer(('127.0.0.1', 9000), logRequests=True, allow_none=True)
server.register_instance(ServerTrial()) 
server.register_introspection_functions()
server.register_multicall_functions()
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
print'This will be printed'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top