1
我需要创建简单的服务器,这将运行某种infite循环,例如:服务器,它西港岛线杀死,并再次运行无限循环
try:
while True:
time.sleep(1)
print ("I'm Running",time.clock())
我需要服务器一段时间后杀死循环,然后再运行它,直到我插入它。你能帮我吗?可能会使用子
我需要创建简单的服务器,这将运行某种infite循环,例如:服务器,它西港岛线杀死,并再次运行无限循环
try:
while True:
time.sleep(1)
print ("I'm Running",time.clock())
我需要服务器一段时间后杀死循环,然后再运行它,直到我插入它。你能帮我吗?可能会使用子
如何:
import time
while True:
try:
time.sleep(1)
print("I'm Running",time.clock())
except KeyboardInterrupt:
print("Don't stop me now! I'm having such a good time...")
time.sleep(x) # instead of x put the number of
# seconds you want before it will start again
正是我需要的,你救了我的一天。谢谢@ nutmeg64 – Ryci
的服务器?为什么不使用瓶子/烧瓶? –
如果你希望它在某个时候结束,它不是无限的!难道你不能制作一个运行无限循环的程序,并使用你的操作系统来启动和停止该服务。 – JeffUK
其实,我的老板需要它来测试子过程,但我不知道如何去做。是的,这不是无限的,但我需要它运行,直到我打断它。中断后,我需要它重新运行并继续。我真的不知道该怎么做。 – Ryci