使用ThreadingMixIn,tensorflow将变量传递给服务器

时间:2017-05-07 13:34:48

标签: python multithreading python-3.x

我有python3代码,它使用ThreadingMixIn实现HttpServer。 问题是我有一个复杂的张量流计算,它在服务器启动时运行。

longComputation = Long_Computation()在里面时(线程化)RequestHandler它可以工作但是每次重建请求都太费时了

当它出局时,如下面的代码,我得到了

TypeError:无法将feed_dict键解释为Tensor:名称“save / Const:0”指的是不存在的Tensor。图中不存在“save / Const”操作。

longComputation  = Long_Computation()

class RequestHandler(BaseHTTPRequestHandler):
            # if i add longComputation  = Long_Computation() here, it works but reruns code for each request
            self.send_response(200) 
            self.end_headers()
            self.send_header('Content-type','application/json')
            length = int(self.headers['content-length'])
            data = self.rfile.read(length).decode('utf-8')

            longComputation.run({'data':data})
            self.wfile.write(bytes(json.dumps({}), "utf8"))
            return  
        return

class ThreadedHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
    """Handle requests in a separate thread."""

def run():
    print('starting server...')

    server_address = ('0.0.0.0', PORT)
    httpd = ThreadedHTTPServer(server_address, RequestHandler)
    httpd.socket = ssl.wrap_socket (httpd.socket, keyfile='/etc/letsencrypt/live/classifier-icici.nanorep-services.com/privkey.pem', certfile='/etc/letsencrypt/live/classifier-icici.nanorep-services.com/cert.pem', server_side=True)
    httpd.serve_forever()

0 个答案:

没有答案