Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
3be11a3a
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看板
提交
3be11a3a
编写于
8月 13, 2021
作者:
H
HexToString
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
temp fix webService and add try catch
上级
6bfaada2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
22 deletion
+36
-22
python/paddle_serving_client/httpclient.py
python/paddle_serving_client/httpclient.py
+34
-20
python/paddle_serving_server/web_service.py
python/paddle_serving_server/web_service.py
+2
-2
未找到文件。
python/paddle_serving_client/httpclient.py
浏览文件 @
3be11a3a
...
...
@@ -197,7 +197,6 @@ class GeneralClient(object):
req
=
json
.
dumps
({})
r
=
requests
.
post
(
encrypt_url
,
req
)
result
=
r
.
json
()
print
(
result
)
if
"endpoint_list"
not
in
result
:
raise
ValueError
(
"server not ready"
)
else
:
...
...
@@ -442,24 +441,36 @@ class GeneralClient(object):
web_url
=
"http://"
+
self
.
ip
+
":"
+
self
.
server_port
+
self
.
service_name
# 当数据区长度大于512字节时才压缩.
if
self
.
try_request_gzip
and
self
.
total_data_number
>
512
:
postData
=
gzip
.
compress
(
bytes
(
postData
,
'utf-8'
))
headers
[
"Content-Encoding"
]
=
"gzip"
if
self
.
try_response_gzip
:
headers
[
"Accept-encoding"
]
=
"gzip"
try
:
if
self
.
try_request_gzip
and
self
.
total_data_number
>
512
:
origin_data
=
postData
postData
=
gzip
.
compress
(
bytes
(
postData
,
'utf-8'
))
headers
[
"Content-Encoding"
]
=
"gzip"
if
self
.
try_response_gzip
:
headers
[
"Accept-encoding"
]
=
"gzip"
# 压缩异常,使用原始数据
except
:
print
(
"compress error, we will use the no-compress data"
)
headers
.
pop
(
"Content-Encoding"
,
"nokey"
)
postData
=
origin_data
# requests支持自动识别解压
result
=
requests
.
post
(
url
=
web_url
,
headers
=
headers
,
data
=
postData
)
if
result
==
None
:
try
:
result
=
requests
.
post
(
url
=
web_url
,
headers
=
headers
,
data
=
postData
)
except
:
print
(
"http post error"
)
return
None
if
result
.
status_code
==
200
:
if
result
.
headers
[
"Content-Type"
]
==
'application/proto'
:
response
=
general_model_service_pb2
.
Response
()
response
.
ParseFromString
(
result
.
content
)
return
response
else
:
return
result
.
json
()
return
result
else
:
if
result
==
None
:
return
None
if
result
.
status_code
==
200
:
if
result
.
headers
[
"Content-Type"
]
==
'application/proto'
:
response
=
general_model_service_pb2
.
Response
()
response
.
ParseFromString
(
result
.
content
)
return
response
else
:
return
result
.
json
()
return
result
def
grpc_client_predict
(
self
,
feed
=
None
,
...
...
@@ -479,10 +490,13 @@ class GeneralClient(object):
endpoints
=
[
self
.
ip
+
":"
+
self
.
server_port
]
g_endpoint
=
'ipv4:{}'
.
format
(
','
.
join
(
endpoints
))
print
(
"my endpoint is "
,
g_endpoint
)
self
.
channel_
=
grpc
.
insecure_channel
(
g_endpoint
,
options
=
options
)
self
.
stub_
=
general_model_service_pb2_grpc
.
GeneralModelServiceStub
(
self
.
channel_
)
resp
=
self
.
stub_
.
inference
(
postData
,
timeout
=
self
.
timeout_ms
)
return
resp
try
:
resp
=
self
.
stub_
.
inference
(
postData
,
timeout
=
self
.
timeout_ms
)
except
:
print
(
"Grpc inference error occur"
)
return
None
else
:
return
resp
python/paddle_serving_server/web_service.py
浏览文件 @
3be11a3a
...
...
@@ -123,7 +123,7 @@ class WebService(object):
workdir
,
port
=
9292
,
gpus
=
None
,
thread_num
=
2
,
thread_num
=
4
,
mem_optim
=
True
,
use_lite
=
False
,
use_xpu
=
False
,
...
...
@@ -236,7 +236,7 @@ class WebService(object):
use_lite
=
False
,
use_xpu
=
False
,
ir_optim
=
False
,
thread_num
=
2
,
thread_num
=
4
,
mem_optim
=
True
,
use_trt
=
False
,
gpu_multi_stream
=
False
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录