From 9340cfe77432b548fc6ace6e2959a07a08e8eadc Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 8 May 2021 18:20:05 +1000 Subject: [PATCH] tests/thread: Make stress_create.py test run on esp32. The esp32 port needs to be idle for finished threads and their resources to be freed up. Signed-off-by: Damien George --- tests/thread/stress_create.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/thread/stress_create.py b/tests/thread/stress_create.py index eda768fa7..877424cdf 100644 --- a/tests/thread/stress_create.py +++ b/tests/thread/stress_create.py @@ -1,9 +1,13 @@ # stress test for creating many threads try: - import utime as time + import utime + + sleep_ms = utime.sleep_ms except ImportError: import time + + sleep_ms = lambda t: time.sleep(t / 1000) import _thread @@ -16,9 +20,11 @@ while thread_num < 500: try: _thread.start_new_thread(thread_entry, (thread_num,)) thread_num += 1 - except MemoryError: - pass + except (MemoryError, OSError) as er: + # Cannot create a new thead at this stage, yield for a bit to + # let existing threads run to completion and free up resources. + sleep_ms(50) # wait for the last threads to terminate -time.sleep(1) +sleep_ms(500) print("done")