Python pyinotify.ThreadedNotifier() Examples

The following are 4 code examples of pyinotify.ThreadedNotifier(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyinotify , or try the search function .
Example #1
Source File: watchers.py    From oslo.log with Apache License 2.0 6 votes vote down vote up
def loop(self):
        """Eventlet friendly ThreadedNotifier

        EventletFriendlyThreadedNotifier contains additional time.sleep()
        call insude loop to allow switching to other thread when eventlet
        is used.
        It can be used with eventlet and native threads as well.
        """

        while not self._stop_event.is_set():
            self.process_events()
            time.sleep(0)
            ref_time = time.time()
            if self.check_events():
                self._sleep(ref_time)
                self.read_events() 
Example #2
Source File: nameTools.py    From IntraArchiveDeduplicator with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def startDirObservers(self, useObservers=True):
		# Observers do not need to be started for simple use, particularly
		# for quick-scripts where the filesystem is not expected to change significantly.
		# Pass useObservers=False to avoid the significant delay
		# in allocating directory observers.


		self.notifierRunning = True
		# Used to check that the directories have been loaded.
		# Should probably be broken up into `notifierRunning` and `dirsLoaded` flags.

		if useObservers:
			if not "wm" in self.__dict__:
				self.wm = pyinotify.WatchManager(exclude_filter=lambda p: os.path.isfile(p))
				self.eventH = EventHandler([item["dir"] for item in self.paths.values()])
				self.notifier = pyinotify.ThreadedNotifier(self.wm, self.eventH)

			self.log.info("Setting up filesystem observers")
			for key in self.paths.keys():
				if not "observer" in self.paths[key]:
					self.log.info("Instantiating observer for path %s", self.paths[key]["dir"])

					self.paths[key]["observer"] = self.wm.add_watch(self.paths[key]["dir"], MONITORED_FS_EVENTS, rec=True)


				else:
					self.log.info("WARNING = DirNameProxy Instantiated multiple times!")

			self.notifier.start()
			self.log.info("Filesystem observers initialized")
			self.log.info("Loading DirLookup")
		else:
			self.eventH = EventHandler([item["dir"] for item in self.paths.values()])

		self.checkUpdate(force=True)
		baseDictKeys = list(self._dirDicts.keys())
		baseDictKeys.sort() 
Example #3
Source File: ext_reload_config.py    From deepWordBug with Apache License 2.0 4 votes vote down vote up
def spawn_watcher(app):
    global NOTIFIER

    # directories to tell inotify to watch
    watched_dirs = []

    # files to actual perform actions on
    watched_files = []

    # watch manager
    wm = pyinotify.WatchManager()

    # watch all config files, and plugin config files
    watched_files = []

    for plugin_dir in app._meta.plugin_config_dirs:
        plugin_dir = fs.abspath(plugin_dir)
        if not os.path.exists(plugin_dir):
            continue

        if plugin_dir not in watched_dirs:
            watched_dirs.append(plugin_dir)

        # just want the first one... looks wierd, but python 2/3 compat
        res = os.walk(plugin_dir)
        for path, dirs, files in os.walk(plugin_dir):
            plugin_config_files = files
            break

        for plugin_config in plugin_config_files:
            full_plugin_path = os.path.join(plugin_dir, plugin_config)
            if full_plugin_path not in watched_files:
                watched_files.append(full_plugin_path)

    for path in app._meta.config_files:
        if os.path.exists(path):
            if path not in watched_files:
                watched_files.append(path)

            this_dir = os.path.dirname(path)
            if this_dir not in watched_dirs:
                watched_dirs.append(this_dir)

    for path in watched_dirs:
        wm.add_watch(path, MASK, rec=True)

    # event handler
    eh = ConfigEventHandler(app, watched_files)

    # notifier
    NOTIFIER = pyinotify.ThreadedNotifier(wm, eh)
    NOTIFIER.start() 
Example #4
Source File: ext_reload_config.py    From jdcloud-cli with Apache License 2.0 4 votes vote down vote up
def spawn_watcher(app):
    global NOTIFIER

    # directories to tell inotify to watch
    watched_dirs = []

    # files to actual perform actions on
    watched_files = []

    # watch manager
    wm = pyinotify.WatchManager()

    # watch all config files, and plugin config files
    watched_files = []

    for plugin_dir in app._meta.plugin_config_dirs:
        plugin_dir = fs.abspath(plugin_dir)
        if not os.path.exists(plugin_dir):
            continue

        if plugin_dir not in watched_dirs:
            watched_dirs.append(plugin_dir)

        # just want the first one... looks wierd, but python 2/3 compat
        # res = os.walk(plugin_dir) ### ?
        for path, dirs, files in os.walk(plugin_dir):
            plugin_config_files = files
            break

        for plugin_config in plugin_config_files:
            full_plugin_path = os.path.join(plugin_dir, plugin_config)
            if full_plugin_path not in watched_files:
                watched_files.append(full_plugin_path)

    for path in app._meta.config_files:
        if os.path.exists(path):
            if path not in watched_files:
                watched_files.append(path)

            this_dir = os.path.dirname(path)
            if this_dir not in watched_dirs:
                watched_dirs.append(this_dir)

    for path in watched_dirs:
        wm.add_watch(path, MASK, rec=True)

    # event handler
    eh = ConfigEventHandler(app, watched_files)

    # notifier
    NOTIFIER = pyinotify.ThreadedNotifier(wm, eh)
    NOTIFIER.start()