Skip to content

Commit

Permalink
A bare thread.join() with no timeout is an invitation to hang the pro…
Browse files Browse the repository at this point in the history
…cess.

Add a timeout to all such instances.
  • Loading branch information
jamadden committed Sep 29, 2021
1 parent 8c26567 commit 5d76ab4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/greenlet/tests/test_contextvars.py
Expand Up @@ -241,7 +241,7 @@ def thread_fn():
gr.gr_context = None

should_exit.set()
thread.join()
thread.join(10)

self.assertEqual(holder, [gr, None])

Expand Down
22 changes: 11 additions & 11 deletions src/greenlet/tests/test_greenlet.py
Expand Up @@ -105,7 +105,7 @@ def f():
for th in ths:
th.start()
for th in ths:
th.join()
th.join(10)
self.assertEqual(len(success), len(ths))

def test_exception(self):
Expand Down Expand Up @@ -174,7 +174,7 @@ def f():
lock.acquire()
self.assertEqual(seen, [greenlet.GreenletExit])
lock2.release()
t.join()
t.join(10)

def test_frame(self):
def f1():
Expand All @@ -200,8 +200,8 @@ def runner(x):
t2 = threading.Thread(target=runner, args=(0.3,))
t1.start()
t2.start()
t1.join()
t2.join()
t1.join(10)
t2.join(10)

def test_switch_kwargs(self):
def run(a, b):
Expand Down Expand Up @@ -240,7 +240,7 @@ def run():
error = sys.exc_info()[1]
self.assertIsNotNone(error, "greenlet.error was not raised!")
done_event.set()
thread.join()
thread.join(10)

def test_exc_state(self):
def f():
Expand Down Expand Up @@ -296,7 +296,7 @@ def setparent(g, value):
g.switch()
self.assertRaises(ValueError, setparent, g, data['g'])
done_event.set()
thread.join()
thread.join(10)

def test_deepcopy(self):
import copy
Expand Down Expand Up @@ -352,7 +352,7 @@ def creator():
result.append(g)
t = threading.Thread(target=creator)
t.start()
t.join()
t.join(10)
self.assertRaises(greenlet.error, result[0].throw, SomeError())

def test_recursive_startup(self):
Expand All @@ -379,7 +379,7 @@ def worker():
g.switch()
t = threading.Thread(target=worker)
t.start()
t.join()
t.join(10)
class convoluted(greenlet):
def __getattribute__(self, name):
if name == 'run':
Expand Down Expand Up @@ -433,7 +433,7 @@ def fthread():
# to randomly crash if it's not anyway.
self.assertEqual(greenlet.getcurrent(), main)
# wait for another thread to complete, just in case
t.join()
t.join(10)

def test_dealloc_switch_args_not_lost(self):
seen = []
Expand Down Expand Up @@ -531,7 +531,7 @@ def __init__(self):
g = None # lose reference to garbage
if recycled[0]:
# gc callback called prematurely
t.join()
t.join(10)
return False
last = greenlet()
if recycled[0]:
Expand All @@ -541,7 +541,7 @@ def __init__(self):
# gc callback not called when expected
gc.collect()
if recycled[0]:
t.join()
t.join(10)
return False
self.assertEqual(last.parent, current)
for g in l:
Expand Down
6 changes: 3 additions & 3 deletions src/greenlet/tests/test_leaks.py
Expand Up @@ -43,7 +43,7 @@ def worker():
t = threading.Thread(target=worker)
t.start()
time.sleep(0.001)
t.join()
t.join(10)

def test_threaded_leak(self):
gg = []
Expand All @@ -53,7 +53,7 @@ def worker():
for _ in range(2):
t = threading.Thread(target=worker)
t.start()
t.join()
t.join(10)
del t
greenlet.getcurrent() # update ts_current
self.recycle_threads()
Expand All @@ -76,7 +76,7 @@ def additional():
for _ in range(2):
t = threading.Thread(target=worker)
t.start()
t.join()
t.join(10)
del t
greenlet.getcurrent() # update ts_current
self.recycle_threads()
Expand Down

0 comments on commit 5d76ab4

Please sign in to comment.