diff options
Diffstat (limited to 'tests/thread/thread_sleep1.py')
| -rw-r--r-- | tests/thread/thread_sleep1.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/thread/thread_sleep1.py b/tests/thread/thread_sleep1.py index add9b02f1..36f775d1f 100644 --- a/tests/thread/thread_sleep1.py +++ b/tests/thread/thread_sleep1.py @@ -12,7 +12,8 @@ else: import _thread lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 n_finished = 0 @@ -24,10 +25,20 @@ def thread_entry(t): n_finished += 1 -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10 * i,)) +# spawn threads +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (10 * n_thread,)) + 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) +n_thread += 1 # wait for threads to finish while n_finished < n_thread: sleep_ms(100) -print("done", n_thread) +print("done") |
