Skip to content

Instantly share code, notes, and snippets.

@yswallow
Created October 26, 2020 23:20
Show Gist options
  • Select an option

  • Save yswallow/cabfbbf031d16ba327feb1bcd51b818d to your computer and use it in GitHub Desktop.

Select an option

Save yswallow/cabfbbf031d16ba327feb1bcd51b818d to your computer and use it in GitHub Desktop.
Pythonのスレッド完全に理解した
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