Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
d85b812e
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看板
提交
d85b812e
编写于
6月 22, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
catch grpc exception inside Client
上级
d7795938
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
82 addition
and
114 deletion
+82
-114
python/examples/grpc_impl_example/criteo_ctr_with_cube/test_client.py
...les/grpc_impl_example/criteo_ctr_with_cube/test_client.py
+2
-7
python/examples/grpc_impl_example/fit_a_line/test_asyn_client.py
...examples/grpc_impl_example/fit_a_line/test_asyn_client.py
+17
-22
python/examples/grpc_impl_example/fit_a_line/test_batch_client.py
...xamples/grpc_impl_example/fit_a_line/test_batch_client.py
+10
-16
python/examples/grpc_impl_example/fit_a_line/test_general_pb_client.py
...es/grpc_impl_example/fit_a_line/test_general_pb_client.py
+9
-16
python/examples/grpc_impl_example/fit_a_line/test_numpy_input_client.py
...s/grpc_impl_example/fit_a_line/test_numpy_input_client.py
+10
-16
python/examples/grpc_impl_example/fit_a_line/test_sync_client.py
...examples/grpc_impl_example/fit_a_line/test_sync_client.py
+9
-15
python/examples/grpc_impl_example/fit_a_line/test_timeout_client.py
...mples/grpc_impl_example/fit_a_line/test_timeout_client.py
+11
-14
python/examples/imdb/test_multilang_ensemble_client.py
python/examples/imdb/test_multilang_ensemble_client.py
+0
-1
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+14
-7
未找到文件。
python/examples/grpc_impl_example/criteo_ctr_with_cube/test_client.py
浏览文件 @
d85b812e
...
...
@@ -39,13 +39,8 @@ for ei in range(10000):
feed_dict
[
'dense_input'
]
=
data
[
0
][
0
]
for
i
in
range
(
1
,
27
):
feed_dict
[
"embedding_{}.tmp_0"
.
format
(
i
-
1
)]
=
data
[
0
][
i
]
try
:
fetch_map
=
client
.
predict
(
feed
=
feed_dict
,
fetch
=
[
"prob"
])
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
else
:
fetch_map
=
client
.
predict
(
feed
=
feed_dict
,
fetch
=
[
"prob"
])
if
fetch_map
[
"status_code"
]
==
0
:
prob_list
.
append
(
fetch_map
[
'prob'
][
0
][
1
])
label_list
.
append
(
data
[
0
][
-
1
][
0
])
...
...
python/examples/grpc_impl_example/fit_a_line/test_asyn_client.py
浏览文件 @
d85b812e
...
...
@@ -14,7 +14,6 @@
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
as
Client
import
paddle
import
functools
import
time
import
threading
...
...
@@ -23,34 +22,30 @@ import grpc
client
=
Client
()
client
.
connect
([
"127.0.0.1:9393"
])
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
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
def
call_back
(
call_future
):
try
:
fetch_map
=
call_future
.
result
()
print
(
fetch_map
)
except
grpc
.
RpcError
as
e
:
print
(
e
.
code
())
finally
:
with
lock
:
complete_task_count
[
0
]
+=
1
x
=
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
]
task_count
=
0
for
data
in
test_reader
():
try
:
future
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"price"
],
asyn
=
True
)
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
else
:
task_count
+=
1
future
.
add_done_callback
(
functools
.
partial
(
call_back
,
data
=
data
))
for
i
in
range
(
3
):
future
=
client
.
predict
(
feed
=
{
"x"
:
x
},
fetch
=
[
"price"
],
asyn
=
True
)
task_count
+=
1
future
.
add_done_callback
(
functools
.
partial
(
call_back
))
while
complete_task_count
[
0
]
!=
task_count
:
time
.
sleep
(
0.1
)
python/examples/grpc_impl_example/fit_a_line/test_batch_client.py
浏览文件 @
d85b812e
...
...
@@ -12,27 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
as
Client
import
paddle
import
grpc
client
=
Client
()
client
.
connect
([
"127.0.0.1:9393"
])
batch_size
=
2
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
batch_size
)
x
=
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
]
for
data
in
test_reader
():
batch_feed
=
[{
"x"
:
x
[
0
]}
for
x
in
data
]
try
:
fetch_map
=
client
.
predict
(
feed
=
batch_feed
,
fetch
=
[
"price"
])
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
else
:
for
i
in
range
(
3
):
batch_feed
=
[{
"x"
:
x
}
for
j
in
range
(
batch_size
)]
fetch_map
=
client
.
predict
(
feed
=
batch_feed
,
fetch
=
[
"price"
])
if
fetch_map
[
"status_code"
]
==
0
:
print
(
fetch_map
)
else
:
print
(
fetch_map
[
"status_code"
])
python/examples/grpc_impl_example/fit_a_line/test_general_pb_client.py
浏览文件 @
d85b812e
...
...
@@ -14,24 +14,17 @@
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
as
Client
import
grpc
import
paddle
client
=
Client
()
client
.
connect
([
"127.0.0.1:9393"
])
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
1
)
for
data
in
test_reader
():
try
:
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"price"
],
is_python
=
False
)
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
x
=
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
]
for
i
in
range
(
3
):
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
x
},
fetch
=
[
"price"
],
is_python
=
False
)
if
fetch_map
[
"status_code"
]
==
0
:
print
(
fetch_map
)
else
:
print
(
"{} {}"
.
format
(
fetch_map
[
"price"
][
0
],
data
[
0
][
1
][
0
])
)
print
(
fetch_map
[
"status_code"
]
)
python/examples/grpc_impl_example/fit_a_line/test_
list
_input_client.py
→
python/examples/grpc_impl_example/fit_a_line/test_
numpy
_input_client.py
浏览文件 @
d85b812e
...
...
@@ -14,24 +14,18 @@
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
as
Client
import
grpc
import
paddle
import
numpy
as
np
client
=
Client
()
client
.
connect
([
"127.0.0.1:9393"
])
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
1
)
for
data
in
test_reader
():
try
:
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
].
tolist
()},
fetch
=
[
"price"
])
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
x
=
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
]
for
i
in
range
(
3
):
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
np
.
array
(
x
)},
fetch
=
[
"price"
])
if
fetch_map
[
"status_code"
]
==
0
:
print
(
fetch_map
)
else
:
print
(
"{} {}"
.
format
(
fetch_map
[
"price"
][
0
],
data
[
0
][
1
][
0
])
)
print
(
fetch_map
[
"status_code"
]
)
python/examples/grpc_impl_example/fit_a_line/test_sync_client.py
浏览文件 @
d85b812e
...
...
@@ -14,23 +14,17 @@
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
as
Client
import
paddle
import
grpc
client
=
Client
()
client
.
connect
([
"127.0.0.1:9393"
])
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
1
)
for
data
in
test_reader
():
try
:
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"price"
])
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
x
=
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
]
for
i
in
range
(
3
):
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
x
},
fetch
=
[
"price"
])
if
fetch_map
[
"status_code"
]
==
0
:
print
(
fetch_map
)
else
:
print
(
"{} {}"
.
format
(
fetch_map
[
"price"
][
0
],
data
[
0
][
1
][
0
])
)
print
(
fetch_map
[
"status_code"
]
)
python/examples/grpc_impl_example/fit_a_line/test_timeout_client.py
浏览文件 @
d85b812e
...
...
@@ -14,24 +14,21 @@
# pylint: disable=doc-string-missing
from
paddle_serving_client
import
MultiLangClient
as
Client
import
paddle
import
grpc
client
=
Client
()
client
.
connect
([
"127.0.0.1:9393"
])
client
.
set_rpc_timeout_ms
(
1
)
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
1
)
for
data
in
test_reader
():
try
:
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"price"
])
except
grpc
.
RpcError
as
e
:
status_code
=
e
.
code
()
if
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
==
status_code
:
print
(
'timeout'
)
x
=
[
0.0137
,
-
0.1136
,
0.2553
,
-
0.0692
,
0.0582
,
-
0.0727
,
-
0.1583
,
-
0.0584
,
0.6283
,
0.4919
,
0.1856
,
0.0795
,
-
0.0332
]
for
i
in
range
(
3
):
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
x
},
fetch
=
[
"price"
])
if
fetch_map
[
"status_code"
]
==
0
:
print
(
fetch_map
)
elif
fetch_map
[
"status_code"
]
==
grpc
.
StatusCode
.
DEADLINE_EXCEEDED
:
print
(
'timeout'
)
else
:
print
(
"{} {}"
.
format
(
fetch_map
[
"price"
][
0
],
data
[
0
][
1
][
0
])
)
print
(
fetch_map
[
"status_code"
]
)
python/examples/imdb/test_multilang_ensemble_client.py
浏览文件 @
d85b812e
...
...
@@ -19,7 +19,6 @@ from imdb_reader import IMDBDataset
client
=
MultiLangClient
()
# If you have more than one model, make sure that the input
# and output of more than one model are the same.
client
.
load_client_config
(
'imdb_bow_client_conf/serving_client_conf.prototxt'
)
client
.
connect
([
"127.0.0.1:9393"
])
# you can define any english sentence or dataset here
...
...
python/paddle_serving_client/__init__.py
浏览文件 @
d85b812e
...
...
@@ -569,6 +569,7 @@ class MultiLangClient(object):
ret
=
multi_result_map
.
values
()[
0
]
else
:
ret
=
multi_result_map
ret
[
"status_code"
]
=
0
return
ret
if
not
need_variant_tag
else
[
ret
,
tag
]
def
_done_callback_func
(
self
,
fetch
,
is_python
,
need_variant_tag
):
...
...
@@ -589,12 +590,15 @@ class MultiLangClient(object):
is_python
=
True
):
req
=
self
.
_pack_inference_request
(
feed
,
fetch
,
is_python
=
is_python
)
if
not
asyn
:
resp
=
self
.
stub_
.
Inference
(
req
,
timeout
=
self
.
rpc_timeout_s_
)
return
self
.
_unpack_inference_response
(
resp
,
fetch
,
is_python
=
is_python
,
need_variant_tag
=
need_variant_tag
)
try
:
resp
=
self
.
stub_
.
Inference
(
req
,
timeout
=
self
.
rpc_timeout_s_
)
return
self
.
_unpack_inference_response
(
resp
,
fetch
,
is_python
=
is_python
,
need_variant_tag
=
need_variant_tag
)
except
grpc
.
RpcError
as
e
:
return
{
"status_code"
:
e
.
code
()}
else
:
call_future
=
self
.
stub_
.
Inference
.
future
(
req
,
timeout
=
self
.
rpc_timeout_s_
)
...
...
@@ -612,7 +616,10 @@ class MultiLangPredictFuture(object):
self
.
callback_func_
=
callback_func
def
result
(
self
):
resp
=
self
.
call_future_
.
result
()
try
:
resp
=
self
.
call_future_
.
result
()
except
grpc
.
RpcError
as
e
:
return
{
"status_code"
:
e
.
code
()}
return
self
.
callback_func_
(
resp
)
def
add_done_callback
(
self
,
fn
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录