[Tutor] Repeat function until...

Nethirlon . nethirlon at gmail.com
Wed Jun 23 14:29:11 CEST 2010


Hello everyone,

I'm new at programming with python and have a question about how I can
solve my problem the correct way. Please forgive my grammar, English
is not my primary language.

I'm looking for a way to repeat my function every 30 seconds.

As an example I have written a ping function. But I would like this
function to repeat itself every 30 seconds, without stopping until I
give it a STOP command (if such a thing exists.)

Code:
import os, sys

def check(host):
    try:
        output = os.popen('ping -ns 1 %s' % host).read()
        alive = output.find('Reply from')
        print alive
        if alive is -1:
            print '%s \t\t DOWN ' % host
        else:
            print '%s \t\t OK' % host
    except OSError, e:
        print e
        sys.exit()

check('www.google.com')

Let me know if anything is unclear or if there are other
recommendations about doing some parts different.

Kind regards,
Nethirlon


More information about the Tutor mailing list