import time
from threading import Thread
stop = False
def some_thread():
while not stop:
print(stop)
time.sleep(0.5)
if __name__ == "__main__":
some_task = Thread(target=some_thread)
some_task.start()
time.sleep(2)
stop = True
some_task.join()