Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ebe24e62
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
ebe24e62
编写于
6月 11, 2021
作者:
C
Chen Weihang
提交者:
GitHub
6月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish unitest test_multiprocess_reader_exception (#33504)
上级
aa50868f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
32 addition
and
43 deletion
+32
-43
python/paddle/fluid/reader.py
python/paddle/fluid/reader.py
+1
-1
python/paddle/fluid/tests/unittests/test_multiprocess_reader_exception.py
...uid/tests/unittests/test_multiprocess_reader_exception.py
+30
-42
python/paddle/reader/decorator.py
python/paddle/reader/decorator.py
+1
-0
未找到文件。
python/paddle/fluid/reader.py
浏览文件 @
ebe24e62
...
@@ -1291,7 +1291,7 @@ class GeneratorLoader(DataLoaderBase):
...
@@ -1291,7 +1291,7 @@ class GeneratorLoader(DataLoaderBase):
except
Exception
as
ex
:
except
Exception
as
ex
:
self
.
_queue
.
kill
()
self
.
_queue
.
kill
()
self
.
_thread
=
None
self
.
_thread
=
None
logging
.
warn
(
'Your reader has raised an exception!'
)
logging
.
warn
ing
(
'Your reader has raised an exception!'
)
six
.
reraise
(
*
sys
.
exc_info
())
six
.
reraise
(
*
sys
.
exc_info
())
self
.
_thread
=
threading
.
Thread
(
self
.
_thread
=
threading
.
Thread
(
...
...
python/paddle/fluid/tests/unittests/test_multiprocess_reader_exception.py
浏览文件 @
ebe24e62
...
@@ -25,7 +25,7 @@ class ReaderException(Exception):
...
@@ -25,7 +25,7 @@ class ReaderException(Exception):
pass
pass
class
TestMultiprocessReaderException
(
unittest
.
TestCase
):
class
TestMultiprocessReaderException
WithQueueSuccess
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
use_pipe
=
False
self
.
use_pipe
=
False
self
.
raise_exception
=
False
self
.
raise_exception
=
False
...
@@ -36,7 +36,7 @@ class TestMultiprocessReaderException(unittest.TestCase):
...
@@ -36,7 +36,7 @@ class TestMultiprocessReaderException(unittest.TestCase):
else
:
else
:
return
[
fluid
.
CPUPlace
()]
return
[
fluid
.
CPUPlace
()]
def
main_impl
(
self
,
place
,
iterable
,
use_legacy_py_reader
):
def
main_impl
(
self
,
place
,
iterable
):
sample_num
=
40
sample_num
=
40
batch_size
=
4
batch_size
=
4
...
@@ -53,37 +53,25 @@ class TestMultiprocessReaderException(unittest.TestCase):
...
@@ -53,37 +53,25 @@ class TestMultiprocessReaderException(unittest.TestCase):
return
__impl__
return
__impl__
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
if
not
use_legacy_py_reader
:
image
=
fluid
.
data
(
name
=
'image'
,
dtype
=
'float32'
,
shape
=
[
None
,
10
])
image
=
fluid
.
data
(
reader
=
fluid
.
io
.
DataLoader
.
from_generator
(
name
=
'image'
,
dtype
=
'float32'
,
shape
=
[
None
,
10
])
reader
=
fluid
.
io
.
PyReader
(
feed_list
=
[
image
],
capacity
=
2
,
iterable
=
iterable
)
feed_list
=
[
image
],
capacity
=
2
,
iterable
=
iterable
)
else
:
reader
=
fluid
.
layers
.
py_reader
(
capacity
=
2
,
shapes
=
[[
-
1
,
10
],
],
dtypes
=
[
'float32'
,
])
image
=
fluid
.
layers
.
read_file
(
reader
)
image_p_1
=
image
+
1
image_p_1
=
image
+
1
decorated_reader
=
multiprocess_reader
(
decorated_reader
=
multiprocess_reader
(
[
fake_reader
(),
fake_reader
()],
use_pipe
=
self
.
use_pipe
)
[
fake_reader
(),
fake_reader
()],
use_pipe
=
self
.
use_pipe
)
if
use_legacy_py_reader
:
reader
.
decorate_paddle_reader
(
fluid
.
io
.
batch
(
decorated_reader
,
batch_size
=
batch_size
))
else
:
if
isinstance
(
place
,
fluid
.
CUDAPlace
):
if
isinstance
(
place
,
fluid
.
CUDAPlace
):
reader
.
decorate
_sample_generator
(
reader
.
set
_sample_generator
(
decorated_reader
,
decorated_reader
,
batch_size
=
batch_size
,
batch_size
=
batch_size
,
places
=
fluid
.
cuda_places
(
0
))
places
=
fluid
.
cuda_places
(
0
))
else
:
else
:
reader
.
decorate
_sample_generator
(
reader
.
set
_sample_generator
(
decorated_reader
,
decorated_reader
,
batch_size
=
batch_size
,
batch_size
=
batch_size
,
places
=
fluid
.
cpu_places
(
))
places
=
fluid
.
cpu_places
(
1
))
exe
=
fluid
.
Executor
(
place
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
exe
.
run
(
fluid
.
default_startup_program
())
...
@@ -97,9 +85,9 @@ class TestMultiprocessReaderException(unittest.TestCase):
...
@@ -97,9 +85,9 @@ class TestMultiprocessReaderException(unittest.TestCase):
for
data
in
reader
():
for
data
in
reader
():
exe
.
run
(
feed
=
data
,
fetch_list
=
[
image_p_1
])
exe
.
run
(
feed
=
data
,
fetch_list
=
[
image_p_1
])
num
+=
1
num
+=
1
self
.
assertEqual
s
(
num
,
batch_num
)
self
.
assertEqual
(
num
,
batch_num
)
except
SystemError
as
ex
:
except
SystemError
as
ex
:
self
.
assertEqual
s
(
num
,
0
)
self
.
assertEqual
(
num
,
0
)
raise
ReaderException
()
raise
ReaderException
()
else
:
else
:
for
_
in
range
(
3
):
for
_
in
range
(
3
):
...
@@ -112,40 +100,40 @@ class TestMultiprocessReaderException(unittest.TestCase):
...
@@ -112,40 +100,40 @@ class TestMultiprocessReaderException(unittest.TestCase):
except
fluid
.
core
.
EOFException
:
except
fluid
.
core
.
EOFException
:
reader
.
reset
()
reader
.
reset
()
self
.
assertFalse
(
self
.
raise_exception
)
self
.
assertFalse
(
self
.
raise_exception
)
self
.
assertEqual
s
(
num
,
batch_num
)
self
.
assertEqual
(
num
,
batch_num
)
except
SystemError
as
ex
:
except
SystemError
as
ex
:
self
.
assertTrue
(
self
.
raise_exception
)
self
.
assertTrue
(
self
.
raise_exception
)
self
.
assertEqual
s
(
num
,
0
)
self
.
assertEqual
(
num
,
0
)
raise
ReaderException
()
raise
ReaderException
()
def
test_main
(
self
):
def
test_main
(
self
):
for
p
in
self
.
places
():
for
p
in
self
.
places
():
for
iterable
in
[
False
,
True
]:
for
iterable
in
[
False
,
True
]:
use_legacy_py_reader_range
=
[
False
]
if
iterable
else
[
False
,
True
]
for
use_legacy_py_reader
in
use_legacy_py_reader_range
:
try
:
try
:
with
fluid
.
scope_guard
(
fluid
.
Scope
()):
with
fluid
.
scope_guard
(
fluid
.
Scope
()):
self
.
main_impl
(
p
,
iterable
,
use_legacy_py_reader
)
self
.
main_impl
(
p
,
iterable
)
self
.
assertTrue
(
not
self
.
raise_exception
)
self
.
assertTrue
(
not
self
.
raise_exception
)
except
ReaderException
:
except
ReaderException
:
self
.
assertTrue
(
self
.
raise_exception
)
self
.
assertTrue
(
self
.
raise_exception
)
class
TestCase1
(
TestMultiprocessReaderException
):
class
TestMultiprocessReaderExceptionWithQueueFailed
(
TestMultiprocessReaderExceptionWithQueueSuccess
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
use_pipe
=
False
self
.
use_pipe
=
False
self
.
raise_exception
=
True
self
.
raise_exception
=
True
class
TestCase2
(
TestMultiprocessReaderException
):
class
TestMultiprocessReaderExceptionWithPipeSuccess
(
TestMultiprocessReaderExceptionWithQueueSuccess
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
use_pipe
=
True
self
.
use_pipe
=
True
self
.
raise_exception
=
False
self
.
raise_exception
=
False
class
TestCase3
(
TestMultiprocessReaderException
):
class
TestMultiprocessReaderExceptionWithPipeFailed
(
TestMultiprocessReaderExceptionWithQueueSuccess
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
use_pipe
=
True
self
.
use_pipe
=
True
self
.
raise_exception
=
True
self
.
raise_exception
=
True
...
...
python/paddle/reader/decorator.py
浏览文件 @
ebe24e62
...
@@ -18,6 +18,7 @@ import multiprocessing
...
@@ -18,6 +18,7 @@ import multiprocessing
import
six
import
six
import
sys
import
sys
import
warnings
import
warnings
import
logging
from
six.moves.queue
import
Queue
from
six.moves.queue
import
Queue
from
six.moves
import
zip_longest
from
six.moves
import
zip_longest
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录