Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix pool release

* fix
  • Loading branch information
zhreshold authored Dec 5, 2018
1 parent f6f8401 commit f6b4665
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/mxnet/gluon/data/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,9 @@ def same_process_iter():

def __len__(self):
return len(self._batch_sampler)

def __del__(self):
if self._worker_pool:
# manually terminate due to a bug that pool is not automatically terminated on linux
assert isinstance(self._worker_pool, multiprocessing.pool.Pool)
self._worker_pool.terminate()
11 changes: 11 additions & 0 deletions tests/python/unittest/test_gluon_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ def test_multi_worker_forked_data_loader():
for i, data in enumerate(loader):
pass

@with_seed()
def test_multi_worker_dataloader_release_pool():
# will trigger too many open file if pool is not released properly
for _ in range(100):
A = np.random.rand(999, 2000)
D = mx.gluon.data.DataLoader(A, batch_size=8, num_workers=8)
the_iter = iter(D)
next(the_iter)
del the_iter
del D

if __name__ == '__main__':
import nose
nose.runmodule()

0 comments on commit f6b4665

Please sign in to comment.