dsoprea / PyInotify

An efficient and elegant inotify (Linux filesystem activity monitor) library for Python. Python 2 and 3 compatible.
GNU General Public License v2.0
242 stars 73 forks source link

Events not firing for os created directories #69

Closed floki2019 closed 5 years ago

floki2019 commented 5 years ago

I modified the test script to monitor network connection file creation and deletion and the events aren't firing. I tested with a different user directory and it worked. This leads me to believe it is a permissions issue. Any thoughts on how to make this work?

`#!/usr/bin/env python3 import time import os from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler

class Watcher: DIRECTORY_TO_WATCH = '/proc/sys/net/ipv4/conf/'

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

def run(self):
    event_handler = Handler()
    self.observer.schedule(event_handler, self.DIRECTORY_TO_WATCH, recursive=True)
    self.observer.start()
    try:
        while True:
            time.sleep(1)
            print('Checking...')
    except Exception as e:
        self.observer.stop()
        print("Error" + str(e))

    self.observer.join()

class Handler(FileSystemEventHandler):

@staticmethod
def on_any_event(event):
    print('Event triggered')
    if event.event_type == 'created':
        print(path + ' created')
    elif event.event_type == 'deleted':
        print(path + ' deleted')

if name == 'main': w = Watcher() w.run()`

floki2019 commented 5 years ago

posted by mistake