本文整理汇总了Python中pyinotify.ThreadedNotifier.setDaemon方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadedNotifier.setDaemon方法的具体用法?Python ThreadedNotifier.setDaemon怎么用?Python ThreadedNotifier.setDaemon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyinotify.ThreadedNotifier
的用法示例。
在下文中一共展示了ThreadedNotifier.setDaemon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileWatcher
# 需要导入模块: from pyinotify import ThreadedNotifier [as 别名]
# 或者: from pyinotify.ThreadedNotifier import setDaemon [as 别名]
class FileWatcher(ProcessEvent):
""" FileWatcher -> Starts an INotify thread to watch a directory for
file changes.
"""
def __init__(self):
""" FileWatcher(directory) -> Watch the directory for changes.
"""
if not pyinotify:
raise Exception("pyinotify is not loaded.")
super(FileWatcher, self).__init__()
self._file_callback_dict = {}
self._watch_manager = WatchManager()
self._events_mask = EventsCodes.ALL_FLAGS['IN_MODIFY']
self._notifier = ThreadedNotifier(self._watch_manager, self)
self._notifier.setDaemon(True)
@classmethod
def check(cls):
""" Returns true if pyinotify is loaded otherwise false.
"""
return pyinotify
def is_running(self):
""" Returns a boolean indecating the state of the notifier.
"""
return self._notifier.isAlive()
def start(self):
""" Start the notifier thread.
"""
self._notifier.start()
def stop(self):
""" Stop the notifier thread.
"""
self._notifier.stop()
def add_directory(self, directory):
""" add_directory(directory) -> Add a directory to watch.
"""
dir_watch = self._watch_manager.add_watch(directory, self._events_mask, rec=True)
def remove_directory(self, directory):
""" remove_directory(directory) -> Remove a directory from the watch.
"""
self._watch_manager.rm_watch(directory, rec=True)
def has_file(self, filename):
""" Returns a boolean indecating if the file is being watched.
"""
return filename in self._file_callback_dict
def add_file(self, filename, callback, *user_data):
""" add_file(filename, callback, *user_data) -> Add a file to watch
with its callback and optional user_data.
"""
self._file_callback_dict[filename] = (callback, user_data)
def remove_file(self, filename):
""" remove_file(filename) -> Remove the file from the watch list.
"""
return self._file_callback_dict.pop(filename, None)
def process_IN_MODIFY(self, event):
""" Process modify events.
"""
filename = os.path.join(event.path, event.name)
callback_data = self._file_callback_dict.get(filename, ())
if callback_data:
callback = callback_data[0]
#.........这里部分代码省略.........