import time import json from urlparse import parse_qs urlparse from Ba

 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
31
32
33
34
import time
import json
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.send_header('Content-type', 'application/json')
self.send_header('Accept', 'text/plain')
self.end_headers()
query = urlparse(self.path).query
o = parse_qs(query, keep_blank_values=True)
# TODO: do work here
time.sleep(300)
response = json.dumps({'response': 'success', 'message': 'test msg'})
self.wfile.write(o['callback'][0] + '(' + response + ')')
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()