Ryci
Ryci

Reputation: 1

Server, which wil kill and again run the infinite loop

I need to create simple server, which will run some kind of infite loop, for example:

try:
  while True:
            time.sleep(1)
            print ("I'm Running",time.clock())

I need server to kill the loop after sometime and then run it again, and everything until i interupt it. Can you help me please? Probably will use subprocess

Upvotes: 1

Views: 59

Answers (1)

bergerg
bergerg

Reputation: 995

How about this:

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

Upvotes: 1

Related Questions