summaryrefslogtreecommitdiff
path: root/tests/thread/thread_gc1.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/thread/thread_gc1.py')
-rw-r--r--tests/thread/thread_gc1.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/tests/thread/thread_gc1.py b/tests/thread/thread_gc1.py
index dd1e64d89..b36ea9d4c 100644
--- a/tests/thread/thread_gc1.py
+++ b/tests/thread/thread_gc1.py
@@ -16,21 +16,34 @@ def thread_entry(n):
data[i] = data[i]
gc.collect()
- # print whether the data remains intact and indicate we are finished
+ # check whether the data remains intact and indicate we are finished
with lock:
- print(list(data) == list(range(256)))
- global n_finished
+ global n_correct, n_finished
+ n_correct += list(data) == list(range(256))
n_finished += 1
lock = _thread.allocate_lock()
-n_thread = 4
+n_thread = 0
+n_thread_max = 4
+n_correct = 0
n_finished = 0
# spawn threads
-for i in range(n_thread):
- _thread.start_new_thread(thread_entry, (10,))
+for _ in range(n_thread_max):
+ try:
+ _thread.start_new_thread(thread_entry, (10,))
+ n_thread += 1
+ except OSError:
+ # System cannot create a new thead, so stop trying to create them.
+ break
+
+# also run the function on this main thread
+thread_entry(10)
+n_thread += 1
# busy wait for threads to finish
while n_finished < n_thread:
pass
+
+print(n_correct == n_finished)