當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。