test_threads.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. #
  3. # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
  4. # Copyright (c) 2024 The Uncertainty Quantification Foundation.
  5. # License: 3-clause BSD. The full license text is available at:
  6. # - https://github.com/uqfoundation/dill/blob/master/LICENSE
  7. import dill
  8. dill.settings['recurse'] = True
  9. def test_new_thread():
  10. import threading
  11. t = threading.Thread()
  12. t_ = dill.copy(t)
  13. assert t.is_alive() == t_.is_alive()
  14. for i in ['daemon','name','ident','native_id']:
  15. if hasattr(t, i):
  16. assert getattr(t, i) == getattr(t_, i)
  17. def test_run_thread():
  18. import threading
  19. t = threading.Thread()
  20. t.start()
  21. t_ = dill.copy(t)
  22. assert t.is_alive() == t_.is_alive()
  23. for i in ['daemon','name','ident','native_id']:
  24. if hasattr(t, i):
  25. assert getattr(t, i) == getattr(t_, i)
  26. def test_join_thread():
  27. import threading
  28. t = threading.Thread()
  29. t.start()
  30. t.join()
  31. t_ = dill.copy(t)
  32. assert t.is_alive() == t_.is_alive()
  33. for i in ['daemon','name','ident','native_id']:
  34. if hasattr(t, i):
  35. assert getattr(t, i) == getattr(t_, i)
  36. if __name__ == '__main__':
  37. test_new_thread()
  38. test_run_thread()
  39. test_join_thread()