Created
October 26, 2020 23:20
-
-
Save yswallow/cabfbbf031d16ba327feb1bcd51b818d to your computer and use it in GitHub Desktop.
Pythonのスレッド完全に理解した
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import threading | |
| import time | |
| def thread1(): | |
| while True: | |
| time.sleep(1) | |
| print("Thread1 running") | |
| if not threading.main_thread().is_alive(): | |
| print("Thread1 exit") | |
| break | |
| if __name__ == "__main__": | |
| threading.Thread(target=thread1).start() | |
| try: | |
| while True: | |
| print("Main Thread running") | |
| time.sleep(0.5) | |
| except KeyboardInterrupt: | |
| print("Main Thread exit by Keyboard Interrupt") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment