[Tutor] [Q] xmlrpcsvr session & threads

Andreas Schöller schoeller@zkm.de
Thu, 4 Oct 2001 15:05:46 +0200


Hello Tutor(s),

i´m using Fredrik Lundh´s xmlrpcserver.py to supply data from a 
mySQL-db. For performance reasons my app caches most of the compound 
info read from the db in a couple of linked objects. This all works. Now 
i want to track user requests and organize them in sessions. AFAIK this 
can be done using cookies ? For browsers with cookies enabled, my 
serving app needs to insert the cookie info into the http-header and 
from that  time on the browser will supply it on every following 
request. I that correct ? I know the cookie module that will do that for 
me. I can extract the complete header at the RequestHandler´s 
call-method ,before any function starts :

def call(self, meth_name, arg_tuple):

		self.location,self.no_clue = self.client_address
		self.header = self.headers
		...

BTW what represents the second value self.no_clue ? It´s a changing 
integer-number ?

Ok, now I can identify the user by it´s ip-addr and/or cookie - but how 
and where can i insert the cookie ? There´s a post-method where this 
should be done, but i´m not sure where or how ?

def do_POST(self):
		
		try:
			# get arguments
			data = self.rfile.read(int(self.headers["content-length"]))
			params, method = xmlrpclib.loads(data)

			# generate response
			try:
				response = self.call(method, params)
				if type(response) != type(()):
					response = (response,)
				# wrap response in a singleton tuple
				#response = (response,)
				
			except xmlrpclib.Fault, faultobj:
				# generated response was a Fault
				response = xmlrpclib.dumps(faultobj)
				print "xmlrpclib-Fault",response
				
			except:
				# report exception back to server
				#print "Standard error..."
				response = xmlrpclib.dumps(xmlrpclib.Fault(1, 
"%s:%s" % (sys.exc_type, sys.exc_value)))
			else:
				response = xmlrpclib.dumps(response,methodresponse=1)
		except:
			# internal error, report as HTTP server error
			print "Interner Fehler ! response=500"
			self.send_response(500)
			self.end_headers()
		else:
			# got a valid XML RPC response
			self.send_response(200)
			self.send_header("Content-type", "text/xml")
			self.send_header("Content-length", str(len(response)))
			self.end_headers()
			self.wfile.write(response)

			# shut down the connection (from Skip Montanaro)
			self.wfile.flush()
			self.connection.shutdown(1)


Maybe somebody can point me the right place where to modify the above 
code-piece.

Furthermore I thought about using threads to increase performance and 
organize the sessions. The resulting amount of data gathered from the db 
is low but number of involved tables is high - about 5-8 tables per 
request. Does it make sense to create a thread per session, that will 
care for the sessions-timeout , logging etc ?
I have a feeling that by using threads i need to change my approach 
considerably ?  Can anybody advise me a direction like threads yes/no 
because ..... the following problems will be small/huge... etc ,, the 
performance gained will be reasonable/quite poor .. etc. ?


thanks in advance ,,, andreas