提交 ef44c30f 编写于 作者: B barrierye

Merge branch 'develop' of https://github.com/PaddlePaddle/Serving into pyserving

...@@ -14,7 +14,10 @@ ...@@ -14,7 +14,10 @@
# pylint: disable=doc-string-missing # pylint: disable=doc-string-missing
from paddle_serving_client import MultiLangClient from paddle_serving_client import MultiLangClient
import functools
import sys import sys
import time
import threading
client = MultiLangClient() client = MultiLangClient()
client.load_client_config(sys.argv[1]) client.load_client_config(sys.argv[1])
...@@ -26,7 +29,22 @@ test_reader = paddle.batch( ...@@ -26,7 +29,22 @@ test_reader = paddle.batch(
paddle.dataset.uci_housing.test(), buf_size=500), paddle.dataset.uci_housing.test(), buf_size=500),
batch_size=1) batch_size=1)
complete_task_count = [0]
lock = threading.Lock()
def call_back(call_future, data):
fetch_map = call_future.result()
print("{} {}".format(fetch_map["price"][0], data[0][1][0]))
with lock:
complete_task_count[0] += 1
task_count = 0
for data in test_reader(): for data in test_reader():
future = client.predict(feed={"x": data[0][0]}, fetch=["price"], asyn=True) future = client.predict(feed={"x": data[0][0]}, fetch=["price"], asyn=True)
fetch_map = future.result() task_count += 1
print("{} {}".format(fetch_map["price"][0], data[0][1][0])) future.add_done_callback(functools.partial(call_back, data=data))
while complete_task_count[0] != task_count:
time.sleep(0.1)
...@@ -431,7 +431,6 @@ class MultiLangClient(object): ...@@ -431,7 +431,6 @@ class MultiLangClient(object):
def _pack_feed_data(self, feed, fetch, is_python): def _pack_feed_data(self, feed, fetch, is_python):
req = multi_lang_general_model_service_pb2.Request() req = multi_lang_general_model_service_pb2.Request()
req.fetch_var_names.extend(fetch) req.fetch_var_names.extend(fetch)
req.feed_var_names.extend(feed.keys())
req.is_python = is_python req.is_python = is_python
feed_batch = None feed_batch = None
if isinstance(feed, dict): if isinstance(feed, dict):
...@@ -440,6 +439,7 @@ class MultiLangClient(object): ...@@ -440,6 +439,7 @@ class MultiLangClient(object):
feed_batch = feed feed_batch = feed
else: else:
raise Exception("{} not support".format(type(feed))) raise Exception("{} not support".format(type(feed)))
req.feed_var_names.extend(feed_batch[0].keys())
init_feed_names = False init_feed_names = False
for feed_data in feed_batch: for feed_data in feed_batch:
inst = multi_lang_general_model_service_pb2.FeedInst() inst = multi_lang_general_model_service_pb2.FeedInst()
...@@ -516,6 +516,9 @@ class MultiLangClient(object): ...@@ -516,6 +516,9 @@ class MultiLangClient(object):
return unpack_resp return unpack_resp
def get_feed_names(self):
return self.feed_names_
def predict(self, def predict(self,
feed, feed,
fetch, fetch,
...@@ -548,3 +551,10 @@ class MultiLangPredictFuture(object): ...@@ -548,3 +551,10 @@ class MultiLangPredictFuture(object):
def result(self): def result(self):
resp = self.call_future_.result() resp = self.call_future_.result()
return self.callback_func_(resp) return self.callback_func_(resp)
def add_done_callback(self, fn):
def __fn__(call_future):
assert call_future == self.call_future_
fn(self)
self.call_future_.add_done_callback(__fn__)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册