Skip to content

Commit

Permalink
tests/thread: Make stress_create.py test run on esp32.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dpgeorge committed May 8, 2021
1 parent 864e4ec commit 9340cfe
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions 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


Expand All @@ -16,9 +20,11 @@ def thread_entry(n):
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")

0 comments on commit 9340cfe

Please sign in to comment.