Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_POST(self):
self.responder =TaskRunnerResponder(self.runner)
call_request_reader = ipc.FramedReader(self.rfile)
call_request = call_request_reader.read_framed_message()
resp_body = self.responder.respond(call_request)
self.send_response(200)
self.send_header('Content-Type', 'avro/binary')
self.end_headers()
resp_writer = ipc.FramedWriter(self.wfile)
resp_writer.write_framed_message(resp_body)
def do_POST(self):
self.responder = responder
call_request_reader = ipc.FramedReader(self.rfile)
call_request = call_request_reader.read_framed_message()
resp_body = self.responder.respond(call_request)
self.send_response(200)
self.send_header('Content-Type', 'avro/binary')
self.end_headers()
resp_writer = ipc.FramedWriter(self.wfile)
resp_writer.write_framed_message(resp_body)
if server_should_shutdown:
print("Shutting down server.", file=sys.stderr)
quitter = threading.Thread(target=self.server.shutdown)
quitter.daemon = True
quitter.start()
def release_lock(self):
self.lock.release()
def timer(self, interval):
self.total += interval
print '{:s}: {:.3f}'.format(self.name, self.total / self.count)
self.count += 1
@classmethod
def create(cls):
if cls.instance is None:
cls.instance = cls()
return cls.instance
class Responder(ipc.Responder):
""" Responder called by handler when got request. """
def __init__(self):
ipc.Responder.__init__(self, PROTOCOL)
def invoke(self, msg, req):
"""
This functino is invoked by do_POST to handle the request. Invoke handles
the request and get response for the request. This is the key of each node.
All models forwarding and output redirect are done here. Because the invoke
method of initializer only needs to receive the data packet, it does not do
anything in the function and return None.
Because this is a node class, it has all necessary code here for handling
different inputs. Basically the logic is load model as the previous layer
request and run model inference. And it will send the current layer output
def do_POST(self):
"""
do_POST is automatically called by ThreadedHTTPServer. It creates a new
responder for each request. The responder generates response and write
response to data sent back.
"""
self.responder = Responder()
call_request_reader = ipc.FramedReader(self.rfile)
call_request = call_request_reader.read_framed_message()
resp_body = self.responder.respond(call_request)
self.send_response(200)
self.send_header('Content-Type', 'avro/binary')
self.end_headers()
resp_writer = ipc.FramedWriter(self.wfile)
resp_writer.write_framed_message(resp_body)
def __init__(self, proto, msg, datum):
proto_json = file(proto, 'r').read()
ipc.Responder.__init__(self, protocol.Parse(proto_json))
self.msg = msg
self.datum = datum
def __init__(self, message):
self._message = message
self._length = len(message)
# We need a buffer length header for every buffer and an additional
# zero-length buffer as the message terminator
self._length += (self._length / ipc.BUFFER_SIZE + 2) \
* ipc.BUFFER_HEADER_LENGTH
self._total_bytes_sent = 0
self._deferred = Deferred()