thread_exit2.py 390 B

12345678910111213141516171819
  1. # test raising SystemExit to finish a 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 thread_entry():
  10. raise SystemExit
  11. _thread.start_new_thread(thread_entry, ())
  12. _thread.start_new_thread(thread_entry, ())
  13. # wait for threads to finish
  14. time.sleep(1)
  15. print('done')