Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
afb05e6b
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看板
提交
afb05e6b
编写于
7月 03, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add load_private_obj func in OP
上级
b96c6019
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
19 deletion
+31
-19
python/pipeline/operator.py
python/pipeline/operator.py
+31
-19
未找到文件。
python/pipeline/operator.py
浏览文件 @
afb05e6b
...
@@ -126,7 +126,7 @@ class Op(object):
...
@@ -126,7 +126,7 @@ class Op(object):
channel
.
add_producer
(
self
.
name
)
channel
.
add_producer
(
self
.
name
)
self
.
_outputs
.
append
(
channel
)
self
.
_outputs
.
append
(
channel
)
def
preprocess
(
self
,
input_dicts
):
def
preprocess
(
self
,
input_dicts
,
private_obj
):
# multiple previous Op
# multiple previous Op
if
len
(
input_dicts
)
!=
1
:
if
len
(
input_dicts
)
!=
1
:
raise
NotImplementedError
(
raise
NotImplementedError
(
...
@@ -136,7 +136,7 @@ class Op(object):
...
@@ -136,7 +136,7 @@ class Op(object):
(
_
,
input_dict
),
=
input_dicts
.
items
()
(
_
,
input_dict
),
=
input_dicts
.
items
()
return
input_dict
return
input_dict
def
process
(
self
,
client_predict_handler
,
feed_dict
):
def
process
(
self
,
client_predict_handler
,
feed_dict
,
private_obj
):
err
,
err_info
=
ChannelData
.
check_npdata
(
feed_dict
)
err
,
err_info
=
ChannelData
.
check_npdata
(
feed_dict
)
if
err
!=
0
:
if
err
!=
0
:
raise
NotImplementedError
(
raise
NotImplementedError
(
...
@@ -146,7 +146,7 @@ class Op(object):
...
@@ -146,7 +146,7 @@ class Op(object):
_LOGGER
.
debug
(
self
.
_log
(
"get call_result"
))
_LOGGER
.
debug
(
self
.
_log
(
"get call_result"
))
return
call_result
return
call_result
def
postprocess
(
self
,
input_dict
,
fetch_dict
):
def
postprocess
(
self
,
input_dict
,
fetch_dict
,
private_obj
):
return
fetch_dict
return
fetch_dict
def
stop
(
self
):
def
stop
(
self
):
...
@@ -197,10 +197,13 @@ class Op(object):
...
@@ -197,10 +197,13 @@ class Op(object):
def
init_op
(
self
):
def
init_op
(
self
):
pass
pass
def
_run_preprocess
(
self
,
parsed_data
,
data_id
,
log_func
):
def
load_private_obj
(
self
):
return
None
def
_run_preprocess
(
self
,
parsed_data
,
data_id
,
private_obj
,
log_func
):
preped_data
,
error_channeldata
=
None
,
None
preped_data
,
error_channeldata
=
None
,
None
try
:
try
:
preped_data
=
self
.
preprocess
(
parsed_data
)
preped_data
=
self
.
preprocess
(
parsed_data
,
private_obj
)
except
NotImplementedError
as
e
:
except
NotImplementedError
as
e
:
# preprocess function not implemented
# preprocess function not implemented
error_info
=
log_func
(
e
)
error_info
=
log_func
(
e
)
...
@@ -227,14 +230,14 @@ class Op(object):
...
@@ -227,14 +230,14 @@ class Op(object):
return
preped_data
,
error_channeldata
return
preped_data
,
error_channeldata
def
_run_process
(
self
,
client_predict_handler
,
preped_data
,
data_id
,
def
_run_process
(
self
,
client_predict_handler
,
preped_data
,
data_id
,
log_func
):
private_obj
,
log_func
):
midped_data
,
error_channeldata
=
None
,
None
midped_data
,
error_channeldata
=
None
,
None
if
self
.
with_serving
:
if
self
.
with_serving
:
ecode
=
ChannelDataEcode
.
OK
.
value
ecode
=
ChannelDataEcode
.
OK
.
value
if
self
.
_timeout
<=
0
:
if
self
.
_timeout
<=
0
:
try
:
try
:
midped_data
=
self
.
process
(
client_predict_handler
,
midped_data
=
self
.
process
(
client_predict_handler
,
preped_data
)
preped_data
,
private_obj
)
except
Exception
as
e
:
except
Exception
as
e
:
ecode
=
ChannelDataEcode
.
UNKNOW
.
value
ecode
=
ChannelDataEcode
.
UNKNOW
.
value
error_info
=
log_func
(
e
)
error_info
=
log_func
(
e
)
...
@@ -245,9 +248,8 @@ class Op(object):
...
@@ -245,9 +248,8 @@ class Op(object):
midped_data
=
func_timeout
.
func_timeout
(
midped_data
=
func_timeout
.
func_timeout
(
self
.
_timeout
,
self
.
_timeout
,
self
.
process
,
self
.
process
,
args
=
(
args
=
(
client_predict_handler
,
preped_data
,
client_predict_handler
,
private_obj
))
preped_data
,
))
except
func_timeout
.
FunctionTimedOut
as
e
:
except
func_timeout
.
FunctionTimedOut
as
e
:
if
i
+
1
>=
self
.
_retry
:
if
i
+
1
>=
self
.
_retry
:
ecode
=
ChannelDataEcode
.
TIMEOUT
.
value
ecode
=
ChannelDataEcode
.
TIMEOUT
.
value
...
@@ -277,10 +279,12 @@ class Op(object):
...
@@ -277,10 +279,12 @@ class Op(object):
midped_data
=
preped_data
midped_data
=
preped_data
return
midped_data
,
error_channeldata
return
midped_data
,
error_channeldata
def
_run_postprocess
(
self
,
input_dict
,
midped_data
,
data_id
,
log_func
):
def
_run_postprocess
(
self
,
input_dict
,
midped_data
,
data_id
,
private_obj
,
log_func
):
output_data
,
error_channeldata
=
None
,
None
output_data
,
error_channeldata
=
None
,
None
try
:
try
:
postped_data
=
self
.
postprocess
(
input_dict
,
midped_data
)
postped_data
=
self
.
postprocess
(
input_dict
,
midped_data
,
private_obj
)
except
Exception
as
e
:
except
Exception
as
e
:
error_info
=
log_func
(
e
)
error_info
=
log_func
(
e
)
_LOGGER
.
error
(
error_info
)
_LOGGER
.
error
(
error_info
)
...
@@ -337,7 +341,7 @@ class Op(object):
...
@@ -337,7 +341,7 @@ class Op(object):
_LOGGER
.
error
(
log
(
e
))
_LOGGER
.
error
(
log
(
e
))
os
.
_exit
(
-
1
)
os
.
_exit
(
-
1
)
#
load user resources
#
init op
try
:
try
:
if
use_multithread
:
if
use_multithread
:
with
self
.
_for_init_op_lock
:
with
self
.
_for_init_op_lock
:
...
@@ -350,6 +354,14 @@ class Op(object):
...
@@ -350,6 +354,14 @@ class Op(object):
_LOGGER
.
error
(
log
(
e
))
_LOGGER
.
error
(
log
(
e
))
os
.
_exit
(
-
1
)
os
.
_exit
(
-
1
)
# load private objects (some no-thread-safe objects)
private_obj
=
None
try
:
private_obj
=
self
.
load_private_obj
()
except
Exception
as
e
:
_LOGGER
.
error
(
log
(
e
))
os
.
_exit
(
-
1
)
self
.
_is_run
=
True
self
.
_is_run
=
True
while
self
.
_is_run
:
while
self
.
_is_run
:
#self._profiler_record("{}-get#{}_0".format(op_info_prefix, tid))
#self._profiler_record("{}-get#{}_0".format(op_info_prefix, tid))
...
@@ -367,8 +379,8 @@ class Op(object):
...
@@ -367,8 +379,8 @@ class Op(object):
# preprecess
# preprecess
self
.
_profiler_record
(
"{}-prep#{}_0"
.
format
(
op_info_prefix
,
tid
))
self
.
_profiler_record
(
"{}-prep#{}_0"
.
format
(
op_info_prefix
,
tid
))
preped_data
,
error_channeldata
=
self
.
_run_preprocess
(
parsed_data
,
preped_data
,
error_channeldata
=
self
.
_run_preprocess
(
data_id
,
log
)
parsed_data
,
data_id
,
private_obj
,
log
)
self
.
_profiler_record
(
"{}-prep#{}_1"
.
format
(
op_info_prefix
,
tid
))
self
.
_profiler_record
(
"{}-prep#{}_1"
.
format
(
op_info_prefix
,
tid
))
if
error_channeldata
is
not
None
:
if
error_channeldata
is
not
None
:
self
.
_push_to_output_channels
(
error_channeldata
,
self
.
_push_to_output_channels
(
error_channeldata
,
...
@@ -378,7 +390,7 @@ class Op(object):
...
@@ -378,7 +390,7 @@ class Op(object):
# process
# process
self
.
_profiler_record
(
"{}-midp#{}_0"
.
format
(
op_info_prefix
,
tid
))
self
.
_profiler_record
(
"{}-midp#{}_0"
.
format
(
op_info_prefix
,
tid
))
midped_data
,
error_channeldata
=
self
.
_run_process
(
midped_data
,
error_channeldata
=
self
.
_run_process
(
client_predict_handler
,
preped_data
,
data_id
,
log
)
client_predict_handler
,
preped_data
,
data_id
,
private_obj
,
log
)
self
.
_profiler_record
(
"{}-midp#{}_1"
.
format
(
op_info_prefix
,
tid
))
self
.
_profiler_record
(
"{}-midp#{}_1"
.
format
(
op_info_prefix
,
tid
))
if
error_channeldata
is
not
None
:
if
error_channeldata
is
not
None
:
self
.
_push_to_output_channels
(
error_channeldata
,
self
.
_push_to_output_channels
(
error_channeldata
,
...
@@ -388,7 +400,7 @@ class Op(object):
...
@@ -388,7 +400,7 @@ class Op(object):
# postprocess
# postprocess
self
.
_profiler_record
(
"{}-postp#{}_0"
.
format
(
op_info_prefix
,
tid
))
self
.
_profiler_record
(
"{}-postp#{}_0"
.
format
(
op_info_prefix
,
tid
))
output_data
,
error_channeldata
=
self
.
_run_postprocess
(
output_data
,
error_channeldata
=
self
.
_run_postprocess
(
parsed_data
,
midped_data
,
data_id
,
log
)
parsed_data
,
midped_data
,
data_id
,
private_obj
,
log
)
self
.
_profiler_record
(
"{}-postp#{}_1"
.
format
(
op_info_prefix
,
tid
))
self
.
_profiler_record
(
"{}-postp#{}_1"
.
format
(
op_info_prefix
,
tid
))
if
error_channeldata
is
not
None
:
if
error_channeldata
is
not
None
:
self
.
_push_to_output_channels
(
error_channeldata
,
self
.
_push_to_output_channels
(
error_channeldata
,
...
@@ -411,7 +423,7 @@ class RequestOp(Op):
...
@@ -411,7 +423,7 @@ class RequestOp(Op):
# PipelineService.name = "#G"
# PipelineService.name = "#G"
super
(
RequestOp
,
self
).
__init__
(
super
(
RequestOp
,
self
).
__init__
(
name
=
"#G"
,
input_ops
=
[],
concurrency
=
concurrency
)
name
=
"#G"
,
input_ops
=
[],
concurrency
=
concurrency
)
#
load user resources
#
init op
try
:
try
:
self
.
init_op
()
self
.
init_op
()
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -436,7 +448,7 @@ class ResponseOp(Op):
...
@@ -436,7 +448,7 @@ class ResponseOp(Op):
def
__init__
(
self
,
input_ops
,
concurrency
=
1
):
def
__init__
(
self
,
input_ops
,
concurrency
=
1
):
super
(
ResponseOp
,
self
).
__init__
(
super
(
ResponseOp
,
self
).
__init__
(
name
=
"#R"
,
input_ops
=
input_ops
,
concurrency
=
concurrency
)
name
=
"#R"
,
input_ops
=
input_ops
,
concurrency
=
concurrency
)
#
load user resources
#
init op
try
:
try
:
self
.
init_op
()
self
.
init_op
()
except
Exception
as
e
:
except
Exception
as
e
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录