[Tutor] Reset while loop

David david at abbottdavid.com
Thu May 7 05:04:42 CEST 2009


bob gailer wrote:

> 
> You call sleep only when the file is updated. As long as the file is not 
> updated the loop runs continuously and therefore 100%.
> 
>> and is there any way to fix it? 
> 
> move the sleep call out of the if, and put the update of old_time in the if
> 
>    while True:
>        new_time = os.stat(fname).st_mtime
>        if new_time > old_time:
>            updated = return_tail(fname, bufsize, linesep)
>            for i in updated:
>                print i
>            old_time = new_time
>        time.sleep(sec_to_wait)

Thank You Bob

-- 
Powered by Gentoo GNU/Linux
http://linuxcrazy.com


More information about the Tutor mailing list