本文整理汇总了Python中pyinotify.ThreadedNotifier方法的典型用法代码示例。如果您正苦于以下问题:Python pyinotify.ThreadedNotifier方法的具体用法?Python pyinotify.ThreadedNotifier怎么用?Python pyinotify.ThreadedNotifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyinotify
的用法示例。
在下文中一共展示了pyinotify.ThreadedNotifier方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loop
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import ThreadedNotifier [as 别名]
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()
示例2: startDirObservers
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import ThreadedNotifier [as 别名]
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()
示例3: spawn_watcher
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import ThreadedNotifier [as 别名]
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()
示例4: spawn_watcher
# 需要导入模块: import pyinotify [as 别名]
# 或者: from pyinotify import ThreadedNotifier [as 别名]
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()