Python http server with multithreaded response handlers
Im trying to setup a python server that handles POST packets. Once a
packet arrives, The do_POST inits a new thread with self & some data,
then, the thread does some stuff and puts into the self object received
the output. its not working at the moment..this is what I tried:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
....
class httpHandler(BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers['content-length'])
data = self.rfile.read(length)
Resolver(self,data).start()
return
Then, In my resolver class I do: import threading
class Resolver(threading.Thread):
def __init__(self,http,number):
threading.Thread.__init__(self)
self.http = http
self.number = number + "!"
def run(self):
self.http.send_response(200)
self.http.send_header('Content-type','text/html')
self.http.send_header('Content-length', len(self.number))
self.http.end_headers()
# Send the html message
self.http.wfile.write(self.number)
return
Of course, this is an example and not the complete sheet, Im still in the
phase testing my stuff. It will be running over a weak platform (at the
moment, Raspberry pi) and Im looking for a good performance solution. What
would you advice me to do?
No comments:
Post a Comment