threading
主線clock迴圈等支線改變running狀態
- from threading import Thread
- from time import ctime,sleep
- running = True
- def func():
- global running
- input()
- running = False
- sleep(3)
- thread = Thread(target = func)
- thread.start()
- while running:
- print(ctime() , end = "\\r")
- sleep(1)
- print("clock stopped")
- thread.join()
- print("thread joined")
支線clock迴圈等主線改變running狀態
- from threading import Thread
- from time import sleep , ctime
- running = True
- def func():
- global running
- while running:
- print(ctime() , end="\\r")
- sleep(1)
- sleep(3)
- thread = Thread(target = func)
- thread.start()
- input()
- running = False
- print("clock stopped")
- thread.join()
- print("thread joined")