circuitpython/tests/thread/stress_create.py
Damien George 9340cfe774 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 <damien@micropython.org>
2021-05-08 22:47:03 +10:00

31 lines
634 B
Python

# stress test for creating many threads
try:
import utime
sleep_ms = utime.sleep_ms
except ImportError:
import time
sleep_ms = lambda t: time.sleep(t / 1000)
import _thread
def thread_entry(n):
pass
thread_num = 0
while thread_num < 500:
try:
_thread.start_new_thread(thread_entry, (thread_num,))
thread_num += 1
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
sleep_ms(500)
print("done")