0
import time
import threading
def do_something():
while True:
time.sleep(0.5)
print('I am alive')
def main():
while True:
time.sleep(1)
print('Hello')
daemon_thread = threading.Thread(target=do_something, daemon=True)
daemon_thread.start()
main()
有沒有一種方法可以讓daemon_thread
從do_something()
以外睡3秒鐘?我的意思是假設像daemon_thread.sleep(3)
?有沒有一種方法可以將線程從線程之外置入睡眠狀態?
你可以使用['queue'](https://docs.python.org/3/library/ queue.html)將睡眠命令傳遞給線程。 – 2016-11-15 07:43:05
@LutzHorn你創建了一個新帳戶嗎? – Maroun
@MarounMaroun? – 2016-11-15 07:47:15