From 27e1a9ee5ac9c2df61f2c1fa7cd3ca96030a3bd1 Mon Sep 17 00:00:00 2001 From: sneaxiy Date: Wed, 20 Feb 2019 12:58:07 +0000 Subject: [PATCH] fix hang bug test=develop --- python/paddle/fluid/reader.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/reader.py b/python/paddle/fluid/reader.py index b765430622e..8352587f23d 100644 --- a/python/paddle/fluid/reader.py +++ b/python/paddle/fluid/reader.py @@ -69,29 +69,32 @@ class PyReader(object): class Iterator(object): def __init__(self, reader): - self._reader = reader + self._reader = reader._reader + self._reset = reader._reset def __iter__(self): return self def next(self): - ret = self._reader._reader.read_next() + ret = self._reader.read_next() if len(ret): return ret else: - self._reader._restart_reader() - self._reader._reader.reset() + self._reset() raise StopIteration return Iterator(self) - def _restart_reader(self): + def _reset(self): if not self._exited: for q in self._queues: q.close() + if self._thread: self._thread.join() + self._reader.reset() + def __thread_main__(): queue_num = len(self._queues) idx = 0 @@ -138,4 +141,4 @@ class PyReader(object): assert self._tensor_reader is None, \ "Cannot reset the data source of PyReader" self._tensor_reader = reader - self._restart_reader() + self._reset() -- GitLab