Skip to content

Commit 06a12ad

Browse files
committed
tests/thread: Add stress-test for creating many threads.
1 parent 2847d74 commit 06a12ad

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/thread/stress_create.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# stress test for creating many threads
2+
3+
try:
4+
import utime as time
5+
except ImportError:
6+
import time
7+
import _thread
8+
9+
def thread_entry(n):
10+
pass
11+
12+
thread_num = 0
13+
while thread_num < 500:
14+
try:
15+
_thread.start_new_thread(thread_entry, (thread_num,))
16+
thread_num += 1
17+
except MemoryError:
18+
pass
19+
20+
# wait for the last threads to terminate
21+
time.sleep(1)
22+
print('done')

0 commit comments

Comments
 (0)