Re: [Tutor] Reset while loop

2009-05-06 Thread David
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 = o

Re: [Tutor] Reset while loop

2009-05-06 Thread David
When running the program cpu usage is 100%. Here is the part that is running; def tail_it(fname, bufsize, linesep): """Update if monitored file time changes""" old_time = os.stat(fname).st_mtime while True: new_time = os.stat(fname).st_mtime if new_time > old_time:

Re: [Tutor] Reset while loop

2009-05-06 Thread Alan Gauld
"David" wrote Alan, thanks for your time and great tips :) You're welcome, I was in a hurry so wasn't sure I understood fully. Here is what I came up with; def print_log_end(fname, bufsize, linesep): f = open(fname, 'r') f.seek(-bufsize, os.SEEK_END)# goto one buffsize away fro

Re: [Tutor] Reset while loop

2009-05-06 Thread David
Alan Gauld wrote: "David" wrote I was playing around with trying to create a python program like tail -f as discussed on the list. i came up with this; Alan, thanks for your time and great tips :) import os def get_tail(fname, bufsize, linesep): f = open(fname, 'rb') f.s

Re: [Tutor] Reset while loop

2009-05-06 Thread Alan Gauld
"Alan Gauld" wrote f.seek(0, 2) pos, tailsize = divmod(f.tell(), bufsize) if tailsize == 0: pos = max(0, pos-1) pos *= bufsize f.seek(pos) I got confused trying to work out exactly what this was doing. pos is initially the number of times b

Re: [Tutor] Reset while loop

2009-05-06 Thread Alan Gauld
"David" wrote I was playing around with trying to create a python program like tail -f as discussed on the list. i came up with this; Some general comments first: def tail_it(bufsize=8192, linesep=__import__('os').linesep): No idea why you are using the import stuff, just use os.linese

[Tutor] Reset while loop

2009-05-05 Thread David
Hi, not even sure if I can ask this very smartly but we shall try: I was playing around with trying to create a python program like tail -f as discussed on the list. i came up with this; def tail_it(bufsize=8192, linesep=__import__('os').linesep): f = None if f == None: f = open