thread_start1.py 435 B

1234567891011121314151617181920212223
  1. # test basic capability to start a new thread
  2. #
  3. # MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
  4. try:
  5. import utime as time
  6. except ImportError:
  7. import time
  8. import _thread
  9. def foo():
  10. pass
  11. def thread_entry(n):
  12. for i in range(n):
  13. foo()
  14. _thread.start_new_thread(thread_entry, (10,))
  15. _thread.start_new_thread(thread_entry, (20,))
  16. # wait for threads to finish
  17. time.sleep(1)
  18. print('done')