Advertisement
Guest User

Untitled

a guest
Dec 24th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import threading
  2. import _thread
  3. import time
  4. import sys
  5. import dis
  6.  
  7. print(__file__)
  8. print(sys.executable)
  9.  
  10. def child_thread():
  11.     time.sleep(1)
  12.     print('child interrupting parent')
  13.     _thread.interrupt_main()
  14.  
  15. dis.dis(child_thread)
  16. dis.dis(sys._getframe().f_code)
  17.  
  18. if __name__ == '__main__':
  19.     t = threading.Thread(target=child_thread, args=())
  20.     t.start()
  21.     print('parent looping')
  22.     try:
  23.         while True:
  24.             time.sleep(1)
  25.     except KeyboardInterrupt:
  26.         print('caught interruption raised from user or child thread :)')
  27.     except TypeError as e:
  28.         print('why would I ever catch a TypeError?')
  29.         print(time.sleep)
  30.         raise
  31.     except Exception as e:
  32.         print('Strange Exception Received ')
  33.         raise
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement