Skip to content

bpo-26762: test_multiprocessing: Fix dangling process/thread #2850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2017
Merged
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
24 changes: 22 additions & 2 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
# without thread support.
import threading

import multiprocessing.dummy
import multiprocessing.connection
import multiprocessing.managers
import multiprocessing.dummy
import multiprocessing.heap
import multiprocessing.managers
import multiprocessing.pool
import multiprocessing.queues

from multiprocessing import util

Expand Down Expand Up @@ -64,6 +65,13 @@
def latin(s):
return s.encode('latin')


def close_queue(queue):
if isinstance(queue, multiprocessing.queues.Queue):
queue.close()
queue.join_thread()


#
# Constants
#
Expand Down Expand Up @@ -825,6 +833,7 @@ def test_qsize(self):
self.assertEqual(q.qsize(), 1)
q.get()
self.assertEqual(q.qsize(), 0)
close_queue(q)

@classmethod
def _test_task_done(cls, q):
Expand Down Expand Up @@ -897,6 +906,7 @@ def __reduce__(self):
q.put(True)
# bpo-30595: use a timeout of 1 second for slow buildbots
self.assertTrue(q.get(timeout=1.0))
close_queue(q)

#
#
Expand Down Expand Up @@ -1020,10 +1030,12 @@ def test_notify(self):
p = self.Process(target=self.f, args=(cond, sleeping, woken))
p.daemon = True
p.start()
self.addCleanup(p.join)

p = threading.Thread(target=self.f, args=(cond, sleeping, woken))
p.daemon = True
p.start()
self.addCleanup(p.join)

# wait for both children to start sleeping
sleeping.acquire()
Expand Down Expand Up @@ -1066,11 +1078,13 @@ def test_notify_all(self):
args=(cond, sleeping, woken, TIMEOUT1))
p.daemon = True
p.start()
self.addCleanup(p.join)

t = threading.Thread(target=self.f,
args=(cond, sleeping, woken, TIMEOUT1))
t.daemon = True
t.start()
self.addCleanup(t.join)

# wait for them all to sleep
for i in range(6):
Expand All @@ -1089,10 +1103,12 @@ def test_notify_all(self):
p = self.Process(target=self.f, args=(cond, sleeping, woken))
p.daemon = True
p.start()
self.addCleanup(p.join)

t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
t.daemon = True
t.start()
self.addCleanup(t.join)

# wait for them to all sleep
for i in range(6):
Expand Down Expand Up @@ -1123,10 +1139,12 @@ def test_notify_n(self):
p = self.Process(target=self.f, args=(cond, sleeping, woken))
p.daemon = True
p.start()
self.addCleanup(p.join)

t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
t.daemon = True
t.start()
self.addCleanup(t.join)

# wait for them to all sleep
for i in range(6):
Expand Down Expand Up @@ -1309,6 +1327,7 @@ def test_event(self):
p.daemon = True
p.start()
self.assertEqual(wait(), True)
p.join()

#
# Tests for Barrier - adapted from tests in test/lock_tests.py
Expand Down Expand Up @@ -1654,6 +1673,7 @@ def test_thousand(self):
p = self.Process(target=self._test_thousand_f,
args=(self.barrier, passes, child_conn, lock))
p.start()
self.addCleanup(p.join)

for i in range(passes):
for j in range(self.N):
Expand Down