Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
3172da66
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看板
提交
3172da66
编写于
7月 28, 2020
作者:
B
barriery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update channel to support timeout
上级
8ec22efb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
23 deletion
+50
-23
python/pipeline/channel.py
python/pipeline/channel.py
+50
-23
未找到文件。
python/pipeline/channel.py
浏览文件 @
3172da66
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=doc-string-missing
from
time
import
time
as
_time
import
threading
import
multiprocessing
import
multiprocessing.queues
...
...
@@ -175,7 +176,7 @@ class ProcessChannel(object):
Only when all types of Ops get the data of the same ID,
the data will be poped; The Op of the same type will not
get the data of the same ID.
3.
(TODO) Timeout and BatchSize are not fully supported
.
3.
Function front support timeout param to make auto-batching
.
Note:
1. The ID of the data in the channel must be different.
...
...
@@ -194,7 +195,7 @@ class ProcessChannel(object):
maintains the data obtained from queue.
"""
def
__init__
(
self
,
manager
,
name
=
None
,
maxsize
=
0
,
timeout
=
None
):
def
__init__
(
self
,
manager
,
name
=
None
,
maxsize
=
0
):
# For queue multiprocess: after putting an object on
# an empty queue there may be an infinitessimal delay
# before the queue's :meth:`~Queue.empty`
...
...
@@ -203,7 +204,6 @@ class ProcessChannel(object):
# - https://hg.python.org/cpython/rev/860fc6a2bd21
self
.
_que
=
manager
.
Queue
(
maxsize
=
maxsize
)
self
.
_maxsize
=
maxsize
self
.
_timeout
=
timeout
self
.
name
=
name
self
.
_stop
=
manager
.
Value
(
'i'
,
0
)
...
...
@@ -327,7 +327,13 @@ class ProcessChannel(object):
self
.
_cv
.
notify_all
()
return
True
def
front
(
self
,
op_name
=
None
):
def
front
(
self
,
op_name
=
None
,
timeout
=
None
):
endtime
=
None
if
timeout
is
not
None
and
timeout
<=
0
:
timeout
=
None
else
:
endtime
=
_time
()
+
timeout
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get data..."
.
format
(
op_name
)))
if
len
(
self
.
_consumer_cursors
)
==
0
:
raise
Exception
(
...
...
@@ -345,16 +351,15 @@ class ProcessChannel(object):
resp
=
self
.
_que
.
get
(
timeout
=
0
)
break
except
Queue
.
Empty
:
_LOGGER
.
debug
(
self
.
_log
(
"{} wait for empty queue(with channel empty: {})"
.
format
(
op_name
,
self
.
_que
.
empty
())))
self
.
_cv
.
wait
()
if
timeout
is
not
None
:
remaining
=
endtime
-
_time
()
if
remaining
<=
0.0
:
raise
ChannelTimeoutError
()
self
.
_cv
.
wait
(
remaining
)
else
:
self
.
_cv
.
wait
()
if
self
.
_stop
.
value
==
1
:
raise
ChannelStopError
()
_LOGGER
.
debug
(
self
.
_log
(
"{} get data succ: {}"
.
format
(
op_name
,
resp
.
__str__
(
))))
return
resp
elif
op_name
is
None
:
raise
Exception
(
...
...
@@ -389,11 +394,13 @@ class ProcessChannel(object):
self
.
_output_buf
.
append
(
channeldata
)
break
except
Queue
.
Empty
:
_LOGGER
.
debug
(
self
.
_log
(
"{} wait for empty queue(with channel size: {})"
.
format
(
op_name
,
self
.
_que
.
qsize
())))
self
.
_cv
.
wait
()
if
timeout
is
not
None
:
remaining
=
endtime
-
_time
()
if
remaining
<=
0.0
:
raise
ChannelTimeoutError
()
self
.
_cv
.
wait
(
remaining
)
else
:
self
.
_cv
.
wait
()
if
self
.
_stop
.
value
==
1
:
raise
ChannelStopError
()
...
...
@@ -458,7 +465,7 @@ class ThreadChannel(Queue.Queue):
Only when all types of Ops get the data of the same ID,
the data will be poped; The Op of the same type will not
get the data of the same ID.
3.
(TODO) Timeout and BatchSize are not fully supported
.
3.
Function front support timeout param to make auto-batching
.
Note:
1. The ID of the data in the channel must be different.
...
...
@@ -477,10 +484,9 @@ class ThreadChannel(Queue.Queue):
maintains the data obtained from queue.
"""
def
__init__
(
self
,
name
=
None
,
maxsize
=-
1
,
timeout
=
None
):
def
__init__
(
self
,
name
=
None
,
maxsize
=-
1
):
Queue
.
Queue
.
__init__
(
self
,
maxsize
=
maxsize
)
self
.
_maxsize
=
maxsize
self
.
_timeout
=
timeout
self
.
name
=
name
self
.
_stop
=
False
...
...
@@ -592,7 +598,13 @@ class ThreadChannel(Queue.Queue):
self
.
_cv
.
notify_all
()
return
True
def
front
(
self
,
op_name
=
None
):
def
front
(
self
,
op_name
=
None
,
timeout
=
None
):
endtime
=
None
if
timeout
is
not
None
and
timeout
<=
0
:
timeout
=
None
else
:
endtime
=
_time
()
+
timeout
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get data"
.
format
(
op_name
)))
if
len
(
self
.
_consumer_cursors
)
==
0
:
raise
Exception
(
...
...
@@ -607,7 +619,13 @@ class ThreadChannel(Queue.Queue):
resp
=
self
.
get
(
timeout
=
0
)
break
except
Queue
.
Empty
:
self
.
_cv
.
wait
()
if
timeout
is
not
None
:
remaining
=
endtime
-
_time
()
if
remaining
<=
0.0
:
raise
ChannelTimeoutError
()
self
.
_cv
.
wait
(
remaining
)
else
:
self
.
_cv
.
wait
()
if
self
.
_stop
:
raise
ChannelStopError
()
_LOGGER
.
debug
(
...
...
@@ -639,7 +657,13 @@ class ThreadChannel(Queue.Queue):
self
.
_output_buf
.
append
(
channeldata
)
break
except
Queue
.
Empty
:
self
.
_cv
.
wait
()
if
timeout
is
not
None
:
remaining
=
endtime
-
_time
()
if
remaining
<=
0.0
:
raise
ChannelTimeoutError
()
self
.
_cv
.
wait
(
remaining
)
else
:
self
.
_cv
.
wait
()
if
self
.
_stop
:
raise
ChannelStopError
()
...
...
@@ -687,6 +711,9 @@ class ThreadChannel(Queue.Queue):
with
self
.
_cv
:
self
.
_cv
.
notify_all
()
class
ChannelTimeoutError
(
RuntimeError
):
def
__init__
(
self
):
pass
class
ChannelStopError
(
RuntimeError
):
def
__init__
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录