本文整理匯總了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()