我有一个脚本,它不能正常工作,所以在bash中,我让脚本在while循环,我想我的脚本可以在一段时间后关闭自己,我试图使用 threading.timer quit() 或 exit() 司令部,有人能帮我吗?
threading.timer
quit()
exit()
#!/usr/bin/env python3 import threading from time import sleep def qu(): print("bye") exit() t=threading.Timer(5.0,qu) t.start() while(True): sleep(1) print("hi")
你可以使用 os._exit 函数而不是 exit()
os._exit
#!/usr/bin/env python3 import threading import os from time import sleep def qu(): print("bye") os._exit(0) t=threading.Timer(5.0,qu) t.start() while(True): sleep(1) print("hi")
无论如何,我建议你结账 this question 因为它和你的相似。