Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix #13521 #13537

Merged
merged 2 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -245,6 +245,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()