Skip to content

Commit 7536432

Browse files
authored
bpo-40275: Fix test.support.threading_helper (GH-20488)
* Add missing sys import * Get verbose and gc_collect() from test.support * Remove unused starttime variable. Issues spotted by pyflakes.
1 parent 24bddc1 commit 7536432

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Lib/test/support/threading_helper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import _thread
12
import contextlib
23
import functools
3-
import _thread
4+
import sys
45
import threading
56
import time
67

@@ -47,7 +48,7 @@ def threading_cleanup(*original_values):
4748
values = None
4849

4950
time.sleep(0.01)
50-
gc_collect()
51+
support.gc_collect()
5152

5253

5354
def reap_threads(func):
@@ -98,7 +99,7 @@ def wait_threads_exit(timeout=None):
9899
f"(count: {count}, old count: {old_count})")
99100
raise AssertionError(msg)
100101
time.sleep(0.010)
101-
gc_collect()
102+
support.gc_collect()
102103

103104

104105
def join_thread(thread, timeout=None):
@@ -124,7 +125,7 @@ def start_threads(threads, unlock=None):
124125
t.start()
125126
started.append(t)
126127
except:
127-
if verbose:
128+
if support.verbose:
128129
print("Can't start %d threads, only %d threads started" %
129130
(len(threads), len(started)))
130131
raise
@@ -133,15 +134,15 @@ def start_threads(threads, unlock=None):
133134
try:
134135
if unlock:
135136
unlock()
136-
endtime = starttime = time.monotonic()
137+
endtime = time.monotonic()
137138
for timeout in range(1, 16):
138139
endtime += 60
139140
for t in started:
140141
t.join(max(endtime - time.monotonic(), 0.01))
141142
started = [t for t in started if t.is_alive()]
142143
if not started:
143144
break
144-
if verbose:
145+
if support.verbose:
145146
print('Unable to join %d threads during a period of '
146147
'%d minutes' % (len(started), timeout))
147148
finally:

0 commit comments

Comments
 (0)