python - Streaming text from a file while its been written to -
is there better , cleaner way stream data text file been written in real time?
at moment im using server simulate data being written continuously , using seek() method read added data , print screen.
the problem im having testing if file been written or not , if not sleep short period test if been written generate , output print screen.
import time seek1 = 198707 seek2 = 198719 file_open = open('c:\users\jay\desktop\tools\uni- server\uniserverz\core\\apache2\logs\\access.log') #c:\users\jay\desktop\tools\uni-server\uniserverz\core\apache2\logs #c:\users\jay\pycharmprojects\parsly\\access.log def generate_list(read_lines):#properly build seek positional checks. #file_object.seek(seek_position) #lines = file_object.readlines() in read_lines: yield def seek_new_postion(generator): listt = [] seek = file_open.tell() old_seek = none counter = 0 while 1: if old_seek == seek , not counter == 5: print "sleeping" time.sleep(1) counter +=1 else: p = generate_list(file_open.readlines()) in p: print time.sleep(1) print "___________________________" print "start seek: %s" % file_open.tell() print "old seek: %s" % old_seek print "___________________________" old_seek = seek seek = file_open.tell() counter = 0 print file_open.tell() in seek_new_postion("test"): print
Comments
Post a Comment