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


Python polling.PollingObserver方法代码示例

本文整理汇总了Python中watchdog.observers.polling.PollingObserver方法的典型用法代码示例。如果您正苦于以下问题:Python polling.PollingObserver方法的具体用法?Python polling.PollingObserver怎么用?Python polling.PollingObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在watchdog.observers.polling的用法示例。


在下文中一共展示了polling.PollingObserver方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_template_observation

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def test_template_observation(task_workbench, app_dir, monkeypatch):
    """Test template folders observations and handling of new template folders.

    Force using PollingObserver to make this run on Travis CI.

    """
    from watchdog.observers.polling import PollingObserver
    from exopy.tasks import plugin
    monkeypatch.setattr(plugin, 'Observer', PollingObserver)

    plugin = task_workbench.get_plugin('exopy.tasks')

    template = os.path.join(app_dir, 'tasks', 'templates', 'test.task.ini')
    with open(template, 'wb'):
        pass

    assert os.path.isfile(template)

    sleep(1.2)

    assert 'test' in plugin.templates 
开发者ID:Exopy,项目名称:exopy,代码行数:23,代码来源:test_plugin.py

示例2: shell_command

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def shell_command(args):
    """
    Subcommand to execute shell commands in response to file system events.

    :param args:
        Command line argument options.
    """
    from watchdog.observers import Observer
    from watchdog.tricks import ShellCommandTrick

    if not args.command:
        args.command = None

    patterns, ignore_patterns = parse_patterns(args.patterns,
                                               args.ignore_patterns)
    handler = ShellCommandTrick(shell_command=args.command,
                                patterns=patterns,
                                ignore_patterns=ignore_patterns,
                                ignore_directories=args.ignore_directories,
                                wait_for_process=args.wait_for_process,
                                drop_during_process=args.drop_during_process)
    observer = Observer(timeout=args.timeout)
    observe_with(observer, handler, args.directories, args.recursive) 
开发者ID:restran,项目名称:hacker-scripts,代码行数:25,代码来源:watchmedo.py

示例3: log

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def log(args):
    """
    Subcommand to log file system events to the console.

    :param args:
        Command line argument options.
    """
    from watchdog.utils import echo
    from watchdog.tricks import LoggerTrick

    if args.trace:
        echo.echo_class(LoggerTrick)

    patterns, ignore_patterns =\
        parse_patterns(args.patterns, args.ignore_patterns)
    handler = LoggerTrick(patterns=patterns,
                          ignore_patterns=ignore_patterns,
                          ignore_directories=args.ignore_directories)
    if args.debug_force_polling:
        from watchdog.observers.polling import PollingObserver as Observer
    elif args.debug_force_kqueue:
        from watchdog.observers.kqueue import KqueueObserver as Observer
    elif args.debug_force_winapi_async:
        from watchdog.observers.read_directory_changes_async import\
            WindowsApiAsyncObserver as Observer
    elif args.debug_force_winapi:
        from watchdog.observers.read_directory_changes import\
            WindowsApiObserver as Observer
    elif args.debug_force_inotify:
        from watchdog.observers.inotify import InotifyObserver as Observer
    elif args.debug_force_fsevents:
        from watchdog.observers.fsevents import FSEventsObserver as Observer
    else:
    # Automatically picks the most appropriate observer for the platform
    # on which it is running.
        from watchdog.observers import Observer
    observer = Observer(timeout=args.timeout)
    observe_with(observer, handler, args.directories, args.recursive) 
开发者ID:restran,项目名称:hacker-scripts,代码行数:40,代码来源:watchmedo.py

示例4: __init__

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def __init__(self, manager):
        self._manager = manager
        self._subscriptions = defaultdict(list)
        self._watchers = {}
        self._observer = PollingObserver(WATCHDOG_POLLING_TIMEOUT)
        self._observer.start() 
开发者ID:dagster-io,项目名称:dagster,代码行数:8,代码来源:local_compute_log_manager.py

示例5: __init__

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def __init__(self, dbfile=":memory:", poll=False):
        self.db = sqlite3.connect(dbfile, check_same_thread=False)
        self.log = logging.getLogger(__name__)
        self._create_db()
#        self.log.warning("I'm warnin' ya!")

        # set up watchdog observer to monitor changes to
        # keyword files (or more correctly, to directories
        # of keyword files)
        self.observer =  PollingObserver() if poll else Observer()
        self.observer.start() 
开发者ID:boakley,项目名称:robotframework-hub,代码行数:13,代码来源:kwdb.py

示例6: shell_command

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def shell_command(args):
    """
    Subcommand to execute shell commands in response to file system events.

    :param args:
        Command line argument options.
    """
    from watchdog.tricks import ShellCommandTrick

    if not args.command:
        args.command = None

    if args.debug_force_polling:
        from watchdog.observers.polling import PollingObserver as Observer
    else:
        from watchdog.observers import Observer

    patterns, ignore_patterns = parse_patterns(args.patterns,
                                               args.ignore_patterns)
    handler = ShellCommandTrick(shell_command=args.command,
                                patterns=patterns,
                                ignore_patterns=ignore_patterns,
                                ignore_directories=args.ignore_directories,
                                wait_for_process=args.wait_for_process,
                                drop_during_process=args.drop_during_process)
    observer = Observer(timeout=args.timeout)
    observe_with(observer, handler, args.directories, args.recursive) 
开发者ID:KenV99,项目名称:script.service.kodi.callbacks,代码行数:29,代码来源:watchmedo.py

示例7: watch_dir

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def watch_dir(self, sld ):
        self.logger.debug("watch_dir %s" % sld )

        if self.force_polling :
           self.logger.info("sr_watch polling observer overriding default (slower but more reliable.)")
           self.observer = PollingObserver()
        else:
           self.logger.info("sr_watch optimal observer for platform selected (best when it works).")
           self.observer = Observer()

        self.obs_watched = []

        self.watch_handler  = SimpleEventHandler(self)
        self.walk_priming(sld)

        self.logger.info("sr_watch priming walk done, but not yet active. Starting...")
        self.observer.start()
        self.logger.info("sr_watch now active on %s posting to exchange: %s"%(sld,self.post_exchange))

        if self.post_on_start:
            self.walk(sld)


    # =============
    # watch_loop
    # ============= 
开发者ID:MetPX,项目名称:sarracenia,代码行数:28,代码来源:sr_post.py

示例8: tricks_from

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def tricks_from(args):
    """
    Subcommand to execute tricks from a tricks configuration file.

    :param args:
        Command line argument options.
    """
    from watchdog.observers import Observer

    add_to_sys_path(path_split(args.python_path))
    observers = []
    for tricks_file in args.files:
        observer = Observer(timeout=args.timeout)

        if not os.path.exists(tricks_file):
            raise IOError("cannot find tricks file: %s" % tricks_file)

        config = load_config(tricks_file)

        try:
            tricks = config[CONFIG_KEY_TRICKS]
        except KeyError:
            raise KeyError("No `%s' key specified in %s." % (
                           CONFIG_KEY_TRICKS, tricks_file))

        if CONFIG_KEY_PYTHON_PATH in config:
            add_to_sys_path(config[CONFIG_KEY_PYTHON_PATH])

        dir_path = os.path.dirname(tricks_file)
        if not dir_path:
            dir_path = os.path.relpath(os.getcwd())
        schedule_tricks(observer, tricks, dir_path, args.recursive)
        observer.start()
        observers.append(observer)

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        for o in observers:
            o.unschedule_all()
            o.stop()
    for o in observers:
        o.join() 
开发者ID:restran,项目名称:hacker-scripts,代码行数:46,代码来源:watchmedo.py

示例9: auto_restart

# 需要导入模块: from watchdog.observers import polling [as 别名]
# 或者: from watchdog.observers.polling import PollingObserver [as 别名]
def auto_restart(args):
    """
    Subcommand to start a long-running subprocess and restart it
    on matched events.

    :param args:
        Command line argument options.
    """
    from watchdog.observers import Observer
    from watchdog.tricks import AutoRestartTrick
    import signal
    import re

    if not args.directories:
        args.directories = ['.']

    # Allow either signal name or number.
    if re.match('^SIG[A-Z]+$', args.signal):
        stop_signal = getattr(signal, args.signal)
    else:
        stop_signal = int(args.signal)

    # Handle SIGTERM in the same manner as SIGINT so that
    # this program has a chance to stop the child process.
    def handle_sigterm(_signum, _frame):
        raise KeyboardInterrupt()

    signal.signal(signal.SIGTERM, handle_sigterm)

    patterns, ignore_patterns = parse_patterns(args.patterns,
                                               args.ignore_patterns)
    command = [args.command]
    command.extend(args.command_args)
    handler = AutoRestartTrick(command=command,
                               patterns=patterns,
                               ignore_patterns=ignore_patterns,
                               ignore_directories=args.ignore_directories,
                               stop_signal=stop_signal,
                               kill_after=args.kill_after)
    handler.start()
    observer = Observer(timeout=args.timeout)
    observe_with(observer, handler, args.directories, args.recursive)
    handler.stop() 
开发者ID:restran,项目名称:hacker-scripts,代码行数:45,代码来源:watchmedo.py


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