diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-06-28 09:21:52 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-06-28 09:21:52 (GMT) |
commit | a79f8faccf5e26f55e8b9496ad49d2071b5e299c (patch) | |
tree | 8fcc1193123bc730a7fbf40a3c572d180bab032f /Lib | |
parent | ccdc09ed1ebea7d7c6b41548132aa08bd797bfe8 (diff) | |
download | cpython-a79f8faccf5e26f55e8b9496ad49d2071b5e299c.zip cpython-a79f8faccf5e26f55e8b9496ad49d2071b5e299c.tar.gz cpython-a79f8faccf5e26f55e8b9496ad49d2071b5e299c.tar.bz2 |
bpo-30775: Fix refleaks in test_multiprocessing (#2467)
Forgetting to call Process.join() can keep some resources alive.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index d4a461d..7dae3c4 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1253,10 +1253,19 @@ class Bunch(object): self._can_exit = namespace.Event() if not wait_before_exit: self._can_exit.set() + + threads = [] for i in range(n): p = namespace.Process(target=self.task) p.daemon = True p.start() + threads.append(p) + + def finalize(threads): + for p in threads: + p.join() + + self._finalizer = weakref.finalize(self, finalize, threads) def task(self): pid = os.getpid() @@ -1279,6 +1288,9 @@ class Bunch(object): def do_finish(self): self._can_exit.set() + def close(self): + self._finalizer() + class AppendTrue(object): def __init__(self, obj): @@ -1311,8 +1323,11 @@ class _TestBarrier(BaseTestCase): def run_threads(self, f, args): b = Bunch(self, f, args, self.N-1) - f(*args) - b.wait_for_finished() + try: + f(*args) + b.wait_for_finished() + finally: + b.close() @classmethod def multipass(cls, barrier, results, n): |