Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
a83cd766
S
Serving
项目概览
PaddlePaddle
/
Serving
1 年多 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a83cd766
编写于
6月 15, 2020
作者:
W
WangXi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
multilang future add call back
上级
e1dfe2ea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
3 deletion
+31
-3
python/examples/fit_a_line/test_multilang_client.py
python/examples/fit_a_line/test_multilang_client.py
+20
-2
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+11
-1
未找到文件。
python/examples/fit_a_line/test_multilang_client.py
浏览文件 @
a83cd766
...
...
@@ -14,7 +14,10 @@
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
import
functools
import
sys
import
time
import
threading
client
=
MultiLangClient
()
client
.
load_client_config
(
sys
.
argv
[
1
])
...
...
@@ -26,7 +29,22 @@ test_reader = paddle.batch(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
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
():
future
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"price"
],
asyn
=
True
)
fetch_map
=
future
.
result
()
print
(
"{} {}"
.
format
(
fetch_map
[
"price"
][
0
],
data
[
0
][
1
][
0
]))
task_count
+=
1
future
.
add_done_callback
(
functools
.
partial
(
call_back
,
data
=
data
))
while
complete_task_count
[
0
]
!=
task_count
:
time
.
sleep
(
0.1
)
python/paddle_serving_client/__init__.py
浏览文件 @
a83cd766
...
...
@@ -431,7 +431,6 @@ class MultiLangClient(object):
def
_pack_feed_data
(
self
,
feed
,
fetch
,
is_python
):
req
=
multi_lang_general_model_service_pb2
.
Request
()
req
.
fetch_var_names
.
extend
(
fetch
)
req
.
feed_var_names
.
extend
(
feed
.
keys
())
req
.
is_python
=
is_python
feed_batch
=
None
if
isinstance
(
feed
,
dict
):
...
...
@@ -440,6 +439,7 @@ class MultiLangClient(object):
feed_batch
=
feed
else
:
raise
Exception
(
"{} not support"
.
format
(
type
(
feed
)))
req
.
feed_var_names
.
extend
(
feed_batch
[
0
].
keys
())
init_feed_names
=
False
for
feed_data
in
feed_batch
:
inst
=
multi_lang_general_model_service_pb2
.
FeedInst
()
...
...
@@ -516,6 +516,9 @@ class MultiLangClient(object):
return
unpack_resp
def
get_feed_names
(
self
):
return
self
.
feed_names_
def
predict
(
self
,
feed
,
fetch
,
...
...
@@ -548,3 +551,10 @@ class MultiLangPredictFuture(object):
def
result
(
self
):
resp
=
self
.
call_future_
.
result
()
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录