Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
ebe24e62
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
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
])
feed_list
=
[
image
],
capacity
=
2
,
iterable
=
iterable
)
reader
=
fluid
.
io
.
PyReader
(
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
:
if
isinstance
(
place
,
fluid
.
CUDAPlace
):
reader
.
decorate_paddle_reader
(
reader
.
set_sample_generator
(
fluid
.
io
.
batch
(
decorated_reader
,
decorated_reader
,
batch_size
=
batch_size
))
batch_size
=
batch_size
,
places
=
fluid
.
cuda_places
(
0
))
else
:
else
:
if
isinstance
(
place
,
fluid
.
CUDAPlace
):
reader
.
set_sample_generator
(
reader
.
decorate_sample_generator
(
decorated_reader
,
decorated_reader
,
batch_size
=
batch_size
,
batch_size
=
batch_size
,
places
=
fluid
.
cpu_places
(
1
))
places
=
fluid
.
cuda_places
(
0
))
else
:
reader
.
decorate_sample_generator
(
decorated_reader
,
batch_size
=
batch_size
,
places
=
fluid
.
cpu_places
())
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
try
:
]
if
iterable
else
[
False
,
True
]
with
fluid
.
scope_guard
(
fluid
.
Scope
()):
for
use_legacy_py_reader
in
use_legacy_py_reader_range
:
self
.
main_impl
(
p
,
iterable
)
try
:
with
fluid
.
scope_guard
(
fluid
.
Scope
()):
self
.
main_impl
(
p
,
iterable
,
use_legacy_py_reader
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录