tail -f in python with no time.sleep

后端 未结 10 1894
耶瑟儿~
耶瑟儿~ 2020-11-30 02:45

I need to emulate \"tail -f\" in python, but I don\'t want to use time.sleep in the reading loop. I want something more elegant like some kind of blocking read, or select.se

10条回答
  •  感情败类
    2020-11-30 03:18

    Why don't you just use subprocess.call on tail itself?

    subproces.call(['tail', '-f', filename])
    

    Edit: Fixed to eliminate extra shell process.

    Edit2: Fixed to eliminate deprecated os.popen and thus the need to interpolate parameters, escape espaces and other stuff, and then run a shell process.

提交回复
热议问题