Watchdog not detecting file directory changes if processes from more than one machineis creating file in a shared network directory

0
Asked by : melany wijngaard 2020-09-10 04:00

I am trying to detect a file in a shared network directory using WatchDog 2.1.6 and Python 3.7.3 The o/s is Linux RHEL. Two machines m1 and m2 have processes that create files in /shared/data/.

If the Watchdog script is running only on m1, it detects changes to the directory in the share - but only if the files are created by processes from machine m1.

If processes from machine m2 creates files in the share, WatchDog does not detect the change.

I would like only one Watchdog based process on just machine m1 to detect files created by processes on /shared/data from any other machine.

The code I am using is below. Any suggestions appreciated.

 import time
from watchdog.observers.polling import PollingObserver
from watchdog.events import FileSystemEventHandler

class OnMyWatch:
    # Set the directory on watch
    watchDirectory = "/shared/data"

    def __init__(self):
        self.observer = PollingObserver()

    def run(self):
        event_handler = Handler()
        self.observer.schedule(event_handler, self.watchDirectory, recursive = True)
        self.observer.start()
        try:
            while True:
                print("Waiting...")
                time.sleep(5)
        except:
            self.observer.stop()
            print("Observer Stopped")

        self.observer.join()


class Handler(FileSystemEventHandler):

     @staticmethod
     def on_any_event(event):
         print(f"Event received.{event.event_type}, {event.src_path}")

if __name__ == '__main__':
    watch = OnMyWatch()
    watch.run()

0 Answers

0 votes
Related Posts
Related Posts
1
Given corners of a quadrilateral, Plot s...
enora aubert enora aubert
2020-01-11  7:05am 2020-01-11 7:05am
2
Error in the Random Forest model fit wit...
laly da silva laly da silva
2021-10-20  4:45am 2021-10-20 4:45am
3
how use SCTP_nodelay in python?...
benjamin beck benjamin beck
2021-04-09  7:33am 2021-04-09 7:33am
4
Creating a new column with value depende...
liam walters liam walters
2021-11-03  2:54pm 2021-11-03 2:54pm
5
Pandas dataframe custom columns and rows...
morgan riviere morgan riviere
2021-04-16  8:53pm 2021-04-16 8:53pm