Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
db5eac2d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
db5eac2d
编写于
5月 07, 2021
作者:
C
Chen Weihang
提交者:
GitHub
5月 07, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add timeout for queue.get (#32747)
上级
7610c2b4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
4 deletion
+21
-4
python/paddle/reader/decorator.py
python/paddle/reader/decorator.py
+21
-4
未找到文件。
python/paddle/reader/decorator.py
浏览文件 @
db5eac2d
...
@@ -17,6 +17,7 @@ import subprocess
...
@@ -17,6 +17,7 @@ import subprocess
import
multiprocessing
import
multiprocessing
import
six
import
six
import
sys
import
sys
import
warnings
from
six.moves.queue
import
Queue
from
six.moves.queue
import
Queue
from
six.moves
import
zip_longest
from
six.moves
import
zip_longest
...
@@ -25,7 +26,9 @@ from six.moves import zip
...
@@ -25,7 +26,9 @@ from six.moves import zip
import
itertools
import
itertools
import
random
import
random
import
zlib
import
zlib
import
paddle.compat
as
cpt
import
paddle.compat
as
cpt
from
paddle.fluid.reader
import
QUEUE_GET_TIMEOUT
__all__
=
[]
__all__
=
[]
...
@@ -584,10 +587,13 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000):
...
@@ -584,10 +587,13 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000):
raise
NotImplementedError
(
raise
NotImplementedError
(
"The multiprocess_reader method is not supported on windows."
)
"The multiprocess_reader method is not supported on windows."
)
# ujson is ultra fast json encoder and decoder written in pure C with bindings for Python 3.6+.
try
:
try
:
import
ujson
as
json
import
ujson
as
json
except
Exception
as
e
:
except
Exception
as
e
:
sys
.
stderr
.
write
(
"import ujson error: "
+
str
(
e
)
+
" use json
\n
"
)
warnings
.
warn
(
"The `ujson` module is not found, use the `json` module, `ujson` encodes and decodes faster, "
"you can install `ujson` through `pip install ujson`."
)
import
json
import
json
assert
isinstance
(
readers
,
(
list
,
tuple
))
and
len
(
readers
)
>
0
,
(
assert
isinstance
(
readers
,
(
list
,
tuple
))
and
len
(
readers
)
>
0
,
(
...
@@ -614,11 +620,20 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000):
...
@@ -614,11 +620,20 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000):
reader_num
=
len
(
readers
)
reader_num
=
len
(
readers
)
finish_num
=
0
finish_num
=
0
while
finish_num
<
reader_num
:
while
finish_num
<
reader_num
:
sample
=
queue
.
get
()
try
:
sample
=
queue
.
get
(
timeout
=
QUEUE_GET_TIMEOUT
)
except
:
logging
.
error
(
"multiprocess_reader failed to get data from the multiprocessing.Queue."
)
six
.
reraise
(
*
sys
.
exc_info
())
if
sample
is
None
:
if
sample
is
None
:
finish_num
+=
1
finish_num
+=
1
elif
sample
==
""
:
elif
sample
==
""
:
raise
ValueError
(
"multiprocess reader raises an exception"
)
raise
ValueError
(
"multiprocess_reader failed to put data into the multiprocessing.Queue."
)
else
:
else
:
yield
sample
yield
sample
...
@@ -660,7 +675,9 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000):
...
@@ -660,7 +675,9 @@ def multiprocess_reader(readers, use_pipe=True, queue_size=1000):
elif
sample
==
""
:
elif
sample
==
""
:
conn
.
close
()
conn
.
close
()
conn_to_remove
.
append
(
conn
)
conn_to_remove
.
append
(
conn
)
raise
ValueError
(
"multiprocess reader raises an exception"
)
raise
ValueError
(
"multiprocess_reader failed to send data into the multiprocessing.Pipe."
)
else
:
else
:
yield
sample
yield
sample
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录