thread_start2.py 603 B

1234567891011121314151617181920212223242526
  1. # test capability to start a thread with keyword args
  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(a0, a1, a2, a3):
  10. print('thread', a0, a1, a2, a3)
  11. # spawn thread using kw args
  12. _thread.start_new_thread(thread_entry, (10, 20), {'a2': 0, 'a3': 1})
  13. # wait for thread to finish
  14. time.sleep(1)
  15. # incorrect argument where dictionary is needed for keyword args
  16. try:
  17. _thread.start_new_thread(thread_entry, (), ())
  18. except TypeError:
  19. print('TypeError')
  20. print('done')