<div class="gmail_quote">On 23 June 2010 13:29, Nethirlon . <span dir="ltr">&lt;<a href="mailto:nethirlon@gmail.com">nethirlon@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Hello everyone,<br>
<br>
I&#39;m new at programming with python and have a question about how I can<br>
solve my problem the correct way. Please forgive my grammar, English<br>
is not my primary language.<br>
<br>
I&#39;m looking for a way to repeat my function every 30 seconds.<br>
<br>
As an example I have written a ping function. But I would like this<br>
function to repeat itself every 30 seconds, without stopping until I<br>
give it a STOP command (if such a thing exists.)<br>
<br>
Code:<br>
import os, sys<br>
<br>
def check(host):<br>
    try:<br>
        output = os.popen(&#39;ping -ns 1 %s&#39; % host).read()<br>
        alive = output.find(&#39;Reply from&#39;)<br>
        print alive<br>
        if alive is -1:<br>
            print &#39;%s \t\t DOWN &#39; % host<br>
        else:<br>
            print &#39;%s \t\t OK&#39; % host<br>
    except OSError, e:<br>
        print e<br>
        sys.exit()<br>
<br>
check(&#39;<a href="http://www.google.com" target="_blank">www.google.com</a>&#39;)<br>
<br>
Let me know if anything is unclear or if there are other<br>
recommendations about doing some parts different.<br>
<br>
Kind regards,<br>
<font color="#888888">Nethirlon</font><br></blockquote><div><font color="#888888"><br></font>You should probably take a look at the time module <a href="http://docs.python.org/library/time.html">http://docs.python.org/library/time.html</a> for waiting (maybe time.sleep)<br>

<br>If you want to call a function an unspecified number of times you probably want a while loop:<br><br>while True:<br>    pass<br><br>loops infinitely unless you quit the program though, to leave the loop you will need to use &quot;break&quot;, you will probably want an if statement and change the value of some variable when you want to stop calling the function and break out of the loop.<br>

<br>HTH,<br>Adam.<br></div></div>