当前位置: 首页>>代码示例>>Python>>正文


Python ThreadedNotifier.setDaemon方法代码示例

本文整理汇总了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]
#.........这里部分代码省略.........
开发者ID:zepto,项目名称:webbrowser,代码行数:103,代码来源:file_watch.py


注:本文中的pyinotify.ThreadedNotifier.setDaemon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。