我不太确定是否可能,但是你可以每隔一秒左右更改raw_input()中的字符串吗? (例如,倒计时)
这是我到目前为止所得到的,
import os, threading, time
varTimeOut = 45
def timeOut():
global varTimeOut
for i in range(45):
varTimeOut = str(45 - i)
os.system("clear")
time.sleep(1)
os.system("sudo reboot")
def main():
global varTimeOut
os.system("clear")
threading.Thread(target=timeOut)
raw_input("System restarting in {} seconds. Press [ENTER] to cancel...".format(varTimeOut))
print("System Restart cancelled!")
main()
这里的每一秒我希望它重新打印raw_input(),如下所示:
System restarting in 45 seconds. Press [ENTER] to cancel...
>1 second later
System restarting in 44 seconds. Press [ENTER] to cancel...
>1 second later
System restarting in 43 seconds. Press [ENTER] to cancel...