Open oonisim opened 11 months ago
This can be expected as https://github.com/dsoprea/PyInotify#notes. The sample code is creating the directory in the same single thread/CPU, then InotifyTree can miss the timing.
IMPORTANT:
Recursively monitoring paths is not a functionality provided by the kernel.
Rather, we artificially implement it. As directory-created events are received,
we create watches for the child directories on-the-fly.
This means that there is potential for a race condition:
if a directory is created and a file or directory is created inside before you
(using the event_gen() loop) have a chance to observe it, then you are going to
have a problem: If it is a file, then you will miss the events related to its
creation, but, if it is a directory, then not only will you miss those creation
events but this library will also miss them and not be able to add a watch for them.
This is also a problem if the directory is created with a mkdir -p
which also create parent directories. Only the first new parent in the tree is noticed.
ie: if /a/b
is being watched and mkdir -p /a/b/c/d/e
is run only the contents of /a/b/c
will be added to the watch. Any subsequent events in /a/b/c/d
or /a/b/c/d/e
will not be captured.
This should be an easy fix. When a dir is added, check if it has subdirs and add them.
I'm not good enough with python to provide a PR, but it seems to me that the add-watch should be calling the __load_trees
but that's in another class.
Environment
Reproducing the issue
If create the directories after monitoring started, file events e.g CLOSE_WAIT do get picked up.
If the directories created in-advance, file events e.g CLOSE_WAIT get picked up.