python - pyinotify bug with reading file on creation? -


I want to parse a file every time that a new file is created in a fixed file. For this, I am trying to use to set up a directory to see IN_CREATE kernel events, and I'm burning fire to the pars () method.

Here is the module:

pyinotify Import Watch Manager, Threaded Notifier, ProcessEvent, from Inquisition Class Watcher (Process): Watchdir = '/ tmp / watch' def __init __ (self): Process Event.__ Init __ (self) Wm = WatchManager () self.notifier = ThreadedNotifier (wm, self) wdd = wm.add_watch (self.watchdir, IN_CREATE) self.notifier.start () def process_IN_CREATE (self, event): pfile = self ._parse (event.pathname) Print (Pfile) def _parse (self, filename): f = open (filename) file = [f.readlines (line) for line) f.close () in return file If __name__ == '__main__' :: Watcher ()

The problem is that _parse D The returned list is empty when triggered by a new file creation event, such as (file watcher.py is running, while in another window) ):

Python watcher.py []

.. But oddly, it works from an interpreter session when called directly is.

  & gt; & Gt; & Gt; Import Watcher & gt; & Gt; & Gt; W = watcher. Water ()> & gt; & Gt; & Gt; W._parse ('/ tmp / clock / sample') ['This is a sample file', 'one more line', 'and second ...']  

Why it is Used to be ? The most far away I've come to debug this thing to know that some pyinotify files are not read correctly but ... why?

Maybe you want to wait until the file closes?


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -