Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
1e548efa
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 2 年 前同步成功
通知
187
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看板
提交
1e548efa
编写于
7月 06, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix queue in multi-process
上级
63cf35d3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
24 deletion
+17
-24
python/pipeline/channel.py
python/pipeline/channel.py
+17
-24
未找到文件。
python/pipeline/channel.py
浏览文件 @
1e548efa
...
@@ -156,7 +156,7 @@ class ChannelData(object):
...
@@ -156,7 +156,7 @@ class ChannelData(object):
ChannelDataType
(
self
.
datatype
).
name
,
self
.
ecode
,
self
.
id
)
ChannelDataType
(
self
.
datatype
).
name
,
self
.
ecode
,
self
.
id
)
class
ProcessChannel
(
multiprocessing
.
queues
.
Queue
):
class
ProcessChannel
(
object
):
"""
"""
(Process version) The channel used for communication between Ops.
(Process version) The channel used for communication between Ops.
...
@@ -186,14 +186,13 @@ class ProcessChannel(multiprocessing.queues.Queue):
...
@@ -186,14 +186,13 @@ class ProcessChannel(multiprocessing.queues.Queue):
"""
"""
def
__init__
(
self
,
manager
,
name
=
None
,
maxsize
=
0
,
timeout
=
None
):
def
__init__
(
self
,
manager
,
name
=
None
,
maxsize
=
0
,
timeout
=
None
):
# https://stackoverflow.com/questions/39496554/cannot-subclass-multiprocessing-queue-in-python-3-5/
# For queue multiprocess: after putting an object on
if
sys
.
version_info
.
major
==
2
:
# an empty queue there may be an infinitessimal delay
super
(
ProcessChannel
,
self
).
__init__
(
maxsize
=
maxsize
)
# before the queue's :meth:`~Queue.empty`
elif
sys
.
version_info
.
major
==
3
:
# see more:
super
(
ProcessChannel
,
self
).
__init__
(
# - https://bugs.python.org/issue18277
maxsize
=
maxsize
,
ctx
=
multiprocessing
.
get_context
())
# - https://hg.python.org/cpython/rev/860fc6a2bd21
else
:
self
.
_que
=
manager
.
Queue
(
maxsize
=
maxsize
)
raise
Exception
(
"Error Python version"
)
self
.
_maxsize
=
maxsize
self
.
_maxsize
=
maxsize
self
.
_timeout
=
timeout
self
.
_timeout
=
timeout
self
.
name
=
name
self
.
name
=
name
...
@@ -255,13 +254,13 @@ class ProcessChannel(multiprocessing.queues.Queue):
...
@@ -255,13 +254,13 @@ class ProcessChannel(multiprocessing.queues.Queue):
with
self
.
_cv
:
with
self
.
_cv
:
while
self
.
_stop
is
False
:
while
self
.
_stop
is
False
:
try
:
try
:
self
.
put
({
op_name
:
channeldata
},
timeout
=
0
)
self
.
_que
.
put
({
op_name
:
channeldata
},
timeout
=
0
)
break
break
except
Queue
.
Full
:
except
Queue
.
Full
:
self
.
_cv
.
wait
()
self
.
_cv
.
wait
()
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
"{} channel size: {}"
.
format
(
op_name
,
self
.
_log
(
"{} channel size: {}"
.
format
(
op_name
,
self
.
qsize
())))
self
.
_que
.
qsize
())))
self
.
_cv
.
notify_all
()
self
.
_cv
.
notify_all
()
_LOGGER
.
debug
(
self
.
_log
(
"{} notify all"
.
format
(
op_name
)))
_LOGGER
.
debug
(
self
.
_log
(
"{} notify all"
.
format
(
op_name
)))
_LOGGER
.
debug
(
self
.
_log
(
"{} push data succ!"
.
format
(
op_name
)))
_LOGGER
.
debug
(
self
.
_log
(
"{} push data succ!"
.
format
(
op_name
)))
...
@@ -305,7 +304,7 @@ class ProcessChannel(multiprocessing.queues.Queue):
...
@@ -305,7 +304,7 @@ class ProcessChannel(multiprocessing.queues.Queue):
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
"{} push data succ: {}"
.
format
(
self
.
_log
(
"{} push data succ: {}"
.
format
(
op_name
,
put_data
.
__str__
())))
op_name
,
put_data
.
__str__
())))
self
.
put
(
put_data
,
timeout
=
0
)
self
.
_que
.
put
(
put_data
,
timeout
=
0
)
break
break
except
Queue
.
Empty
:
except
Queue
.
Empty
:
self
.
_cv
.
wait
()
self
.
_cv
.
wait
()
...
@@ -329,20 +328,20 @@ class ProcessChannel(multiprocessing.queues.Queue):
...
@@ -329,20 +328,20 @@ class ProcessChannel(multiprocessing.queues.Queue):
try
:
try
:
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get(with channel empty: {})"
.
self
.
_log
(
"{} try to get(with channel empty: {})"
.
format
(
op_name
,
self
.
empty
())))
format
(
op_name
,
self
.
_que
.
empty
())))
# For queue multiprocess: after putting an object on
# For queue multiprocess: after putting an object on
# an empty queue there may be an infinitessimal delay
# an empty queue there may be an infinitessimal delay
# before the queue's :meth:`~Queue.empty`
# before the queue's :meth:`~Queue.empty`
# see more:
# see more:
# - https://bugs.python.org/issue18277
# - https://bugs.python.org/issue18277
# - https://hg.python.org/cpython/rev/860fc6a2bd21
# - https://hg.python.org/cpython/rev/860fc6a2bd21
resp
=
self
.
get
(
timeout
=
1e-3
)
resp
=
self
.
_que
.
get
(
timeout
=
1e-3
)
break
break
except
Queue
.
Empty
:
except
Queue
.
Empty
:
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
self
.
_log
(
"{} wait for empty queue(with channel empty: {})"
.
"{} wait for empty queue(with channel empty: {})"
.
format
(
op_name
,
self
.
empty
())))
format
(
op_name
,
self
.
_que
.
empty
())))
self
.
_cv
.
wait
()
self
.
_cv
.
wait
()
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
"{} get data succ: {}"
.
format
(
op_name
,
resp
.
__str__
(
self
.
_log
(
"{} get data succ: {}"
.
format
(
op_name
,
resp
.
__str__
(
...
@@ -376,21 +375,15 @@ class ProcessChannel(multiprocessing.queues.Queue):
...
@@ -376,21 +375,15 @@ class ProcessChannel(multiprocessing.queues.Queue):
try
:
try
:
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
"{} try to get(with channel size: {})"
.
format
(
self
.
_log
(
"{} try to get(with channel size: {})"
.
format
(
op_name
,
self
.
qsize
())))
op_name
,
self
.
_que
.
qsize
())))
# For queue multiprocess: after putting an object on
channeldata
=
self
.
_que
.
get
(
timeout
=
1e-3
)
# an empty queue there may be an infinitessimal delay
# before the queue's :meth:`~Queue.empty`
# see more:
# - https://bugs.python.org/issue18277
# - https://hg.python.org/cpython/rev/860fc6a2bd21
channeldata
=
self
.
get
(
timeout
=
1e-3
)
self
.
_output_buf
.
append
(
channeldata
)
self
.
_output_buf
.
append
(
channeldata
)
break
break
except
Queue
.
Empty
:
except
Queue
.
Empty
:
_LOGGER
.
debug
(
_LOGGER
.
debug
(
self
.
_log
(
self
.
_log
(
"{} wait for empty queue(with channel size: {})"
.
"{} wait for empty queue(with channel size: {})"
.
format
(
op_name
,
self
.
qsize
())))
format
(
op_name
,
self
.
_que
.
qsize
())))
self
.
_cv
.
wait
()
self
.
_cv
.
wait
()
consumer_cursor
=
self
.
_consumer_cursors
[
op_name
]
consumer_cursor
=
self
.
_consumer_cursors
[
op_name
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录