import time from urlparse import parse_qs urlparse from BaseHTTPServer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
from urlparse import parse_qs, urlparse
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
query = urlparse(self.path).query
parse_qs(query, keep_blank_values=True)
# TODO: do work here
time.sleep(10)
self.wfile.write('Success')
return
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
"""Handle requests in a separate thread."""
if __name__ == '__main__':
server = ThreadedHTTPServer(('localhost', 8888), Handler)
print 'Starting server, use <Ctrl-C> to stop'
server.serve_forever()