1

I am doing an app whit wxPython and XMLRPC i need that the window does an action every time the XMLRPC server has a request

How could i do it without blocking the main Window?

I tried with threads but it doesnt work also I tried calling the run method of the thread in the Frame's constructor neither it worked

Sorry for the language I hope to be clear Thanks

2
  • 1
    Can you show us your code? Also, what do you mean by it doesn't work - do you get an exception, traceback, segfault? It would help if you could post the actual results you're getting. Commented Nov 29, 2012 at 5:38
  • You could start a new thread for handling the new request, just remember to use wx.CallAfter when trying to update the GUI from the new thread. Commented Nov 29, 2012 at 21:36

1 Answer 1

1

Here's an example of a threaded XMLRPC server using SimpleXMLRPCServer. Note the wx.CallAfter to call into the wx main thread and the "return 0" (though you can configure the server so that return values of None are OK.)

from SimpleXMLRPCServer import SimpleXMLRPCServer
import threading

class XMLRPCServerThread(threading.Thread):
    def __init__(self, remoteObject, host='localhost', port=8000):
        self.remoteObject = remoteObject
        self.host = host
        self.port = port
        threading.Thread.__init__(self)

    def stop(self):
        self.server.shutdown()    

    def run(self):
        self.server = SimpleXMLRPCServer( (self.host, self.port), logRequests=False )
        self.server.register_instance( self.remoteObject )
        self.server.serve_forever()

class MyRemoteCalls(object):

    def __init__(self, obj):
        self.obj = obj

    def exampleCall(self, arg):
        wx.CallAfter(self.obj.method, arg)
        return 0  

def getRPCThread(obj, host='localhost', port=8000):
    remoteObj = MyRemoteCalls(obj)
    rpcThread = XMLRPCServerThread(remoteObj, host, port)
    rpcThread.start()
    return rpcThread
Sign up to request clarification or add additional context in comments.

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.