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

Commit f6b4665

Browse files
authored
Fix #13521 (#13537)
* fix pool release * fix
1 parent f6f8401 commit f6b4665

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

python/mxnet/gluon/data/dataloader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,9 @@ def same_process_iter():
556556

557557
def __len__(self):
558558
return len(self._batch_sampler)
559+
560+
def __del__(self):
561+
if self._worker_pool:
562+
# manually terminate due to a bug that pool is not automatically terminated on linux
563+
assert isinstance(self._worker_pool, multiprocessing.pool.Pool)
564+
self._worker_pool.terminate()

tests/python/unittest/test_gluon_data.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ def test_multi_worker_forked_data_loader():
244244
for i, data in enumerate(loader):
245245
pass
246246

247+
@with_seed()
248+
def test_multi_worker_dataloader_release_pool():
249+
# will trigger too many open file if pool is not released properly
250+
for _ in range(100):
251+
A = np.random.rand(999, 2000)
252+
D = mx.gluon.data.DataLoader(A, batch_size=8, num_workers=8)
253+
the_iter = iter(D)
254+
next(the_iter)
255+
del the_iter
256+
del D
257+
247258
if __name__ == '__main__':
248259
import nose
249260
nose.runmodule()

0 commit comments

Comments
 (0)