Skip to content

Instantly share code, notes, and snippets.

@cftang0827
Created November 13, 2018 06:23
Show Gist options
  • Save cftang0827/1c2f319a7517a3dc2f75394eb1b29c4f to your computer and use it in GitHub Desktop.
Save cftang0827/1c2f319a7517a3dc2f75394eb1b29c4f to your computer and use it in GitHub Desktop.
import time
import threading
class p:
def __init__(self):
self.flag = True
self.thread = threading.Thread(target=self.show)
self.thread.start()
def show(self):
while True:
if self.flag:
print("Hello")
else:
print("dead")
break
p1 = p()
time.sleep(3)
p1.flag = False
print(p1.thread.is_alive())
p1.thread.join()
print(p1.thread.is_alive())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment