1

I'm working with a csv file that's constantly growing, with about 20 lines being added per second. Each line needs to be parsed. The code snippet I have below does work, but it seems to stop updating after a bit. It's running in its own thread and if I manually update the csv file (ie. a new line every few seconds), it seems to work perfectly fine.

file=open('data.csv', 'r')
while True:
    line=file.readline()
    if len(line) > 2:
        print(line)
        #parse

This is on Ubuntu 14.04 and Python 3.5 (unfortunately, I'm stuck with these versions). Strangely enough, I haven't noticed any issues when running on Windows 7. Is there a better way to approach this?

1 Answers1

1

Since OP has claimed that the file is appended then I would suggest to try answers to How can I tail a log file in Python?. In short, you could do:

  • Your python script should use the built-in tail and check return from the tail.

  • Use an external python module named sh

duong_dajgja
  • 4,196
  • 1
  • 38
  • 65