这里有两个脚本。一个是主脚本,另一个是Server Handler。通过主脚本Im调用Handler。 服务器将启动但无法发送响应。 请帮助我。
主要文字:
def start_server(message_queue):
print time.asctime(), "Server Start - %s:%s" % (HOST_NAME, PORT)
httpd = SocketServer.ThreadingTCPServer((HOST_NAME, PORT), ServerHandler(message_queue))
httpd.serve_forever()
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT)
if __name__ == '__main__':
logging.basicConfig(filename=LOG_PATH, level=LOG_LEVEL, format='%(asctime)s-%(levelname)s-%(message)s')
queue = Queue()
process_new = Process(target=start_server, args=(queue,))
process_new.start()
queue.put("INSUFFICIENT_CREDIT")
服务器处理程序:
class ServerHandler(SocketServer.ThreadingMixIn,SimpleHTTPServer.SimpleHTTPRequestHandler):
def __init__(self, message_queue):
self.queue = message_queue
def do_POST(self,message_queue):
message = message_queue.get()
if message is None:
print "Test result"
else:
"SUCCESS"
self.send_response(200)
self.end_headers()