tail -f in python with no time.sleep

后端 未结 10 1891
耶瑟儿~
耶瑟儿~ 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:13

    IMO you should use sleep, it works on all platform and code will be simple

    Otherwise you can use platform specific APIs which can tell you when file change e.g. on window use FindFirstChangeNotification on folder and watch for FILE_NOTIFY_CHANGE_LAST_WRITE events

    On linux i think you can use i-notify

    On Mac OSX use FSEvents

提交回复
热议问题