[Tutor] Socket server and threads
Rob Brown-Bayliss
rob@zoism.org
17 Sep 2002 11:00:14 +1200
Hi, I am trying to write an app. it Has a gui, and I am using xmlrpc via
socket server to communicate with other apps on other machines.
I currently have the socket server running as a thread like so:
args = (('', 48002), BHH_Communication.BHH_DMHandler, self)
self.server = None
self.tserver = thread.start_new_thread(BHH_Communication.BHH_TCPServer,
args)
while (self.server == None):
pass
where BHH_TPCServer is:
class BHH_TCPServer(SocketServer.TCPServer):
def __init__(self, server_address, RequestHandlerClass, parent):
SocketServer.TCPServer.__init__(self, server_address,
RequestHandlerClass)
self.BHH = parent
self.BHH.server = self # so handlers have access to # GUI app
self.in_comms = []
self.in_comms.append(self)
self.out_comms = []
while 1:
rtoread, rtowrite, err = select.select(self.in_comms ,
self.out_comms, [], 5.0)
if (len(rtoread) != 0):
rtoread[0].handle_request()
So with this my handler class can call functions in the main app via
self.server.BHH.some_function()
My question is what do I need to do to make sure it is safe, what
happens if the thread and the parent app are trying to call the same
function at the same time? What about if two or more request handlers
are running and want the same function at the same time (via a threaded
TCP handler class?
Thanks
--
*
* Rob Brown-Bayliss
*