stress_create.py 395 B

12345678910111213141516171819202122
  1. # stress test for creating many threads
  2. try:
  3. import utime as time
  4. except ImportError:
  5. import time
  6. import _thread
  7. def thread_entry(n):
  8. pass
  9. thread_num = 0
  10. while thread_num < 500:
  11. try:
  12. _thread.start_new_thread(thread_entry, (thread_num,))
  13. thread_num += 1
  14. except MemoryError:
  15. pass
  16. # wait for the last threads to terminate
  17. time.sleep(1)
  18. print('done')