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


Python observers.Observer方法代码示例

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


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

示例1: __init__

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def __init__(self):
        if Observer is not None and not judgeenv.no_watchdog:
            if judgeenv.env.update_pings:
                logger.info('Using thread to ping urls: %r', judgeenv.env.update_pings)
                self._refresher = RefreshWorker(judgeenv.env.update_pings)
            else:
                self._refresher = None

            self._handler = SendProblemsHandler(self._refresher)
            self._monitor = Observer()
            for dir in get_problem_watches():
                self._monitor.schedule(self._handler, dir, recursive=True)
                logger.info('Scheduled for monitoring: %s', dir)
        else:
            self._monitor = None
            self._refresher = None 
开发者ID:DMOJ,项目名称:judge-server,代码行数:18,代码来源:monitor.py

示例2: watch

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watch():
    is_proj, root = get_project_root()

    state = {"dirty": False}

    if not is_proj:
        click.echo("Run psync to generate .psync config file.")
    else:
        click.echo("Start watching {} ...".format(root))
        event_handler = watcher.AnyEventHandler(state)
        observer = Observer()
        observer.schedule(event_handler, root, recursive=True)
        observer.start()
        try:
            while True:
                if state["dirty"]:
                    click.echo("Detect modification. Perform sync.")
                    perform_sync()
                    state["dirty"] = False
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join() 
开发者ID:lazywei,项目名称:psync,代码行数:25,代码来源:cli.py

示例3: main

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def main(watch):
    # Regenerate at least once.
    regenerate()

    if watch:
        observer = Observer()

        # Observe both the template directory and cookiecutter.json.
        observer.schedule(RegenerateSugardoughHandler(), TEMPLATEDIR, recursive=True)
        cookiecutter_json_handler = RegenerateSugardoughHandler(patterns=[
            os.path.join(BASEDIR, 'cookiecutter.json')
        ])
        observer.schedule(cookiecutter_json_handler, BASEDIR)

        print('Watching for changes...')
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
        observer.join() 
开发者ID:mozilla,项目名称:sugardough,代码行数:24,代码来源:regenerate.py

示例4: start

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def start(cls, config):
        """
        The starter method for watching files.
        If invoked, it will start watching all files and see if documentation is needed

        Parameters
        ----------
        ConfigParser config: Config going to be used in DYC
        """
        logging.basicConfig(level=logging.INFO)
        observer = Observer()
        event_handler = WatchEvent()
        event_handler.config = config
        observer.schedule(event_handler, '.', recursive=True)
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
            print('Quitting..')
        observer.join() 
开发者ID:Zarad1993,项目名称:dyc,代码行数:24,代码来源:events.py

示例5: watchdir

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watchdir():
    try:
        global watchdog_handler
        logger.debug('Initializing watchdog')
        observer = Observer()
        observer.schedule(watchdog_handler, path=cfg.watchdir_location, recursive=True)
        observer.start()
        logger.debug('Initializing watchdog complete')
        if cfg.watchdir_walk_enabled:
            scheduler.scheduler.add_job(walk_watchdir, 'interval', id='walk_watchdir', seconds=active_interval,
                                        replace_existing=True, max_instances=1, coalesce=True)
        else:
            walk_watchdir()

    except:
        raise


# Flask 
开发者ID:piejanssens,项目名称:premiumizer,代码行数:21,代码来源:premiumizer.py

示例6: _bind_observers

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def _bind_observers(self):
        """Start the observers.

        """
        for contrib in ('users', 'starters', 'connections', 'settings'):
            callback = partial(self._update_contribs, contrib)
            getattr(self, '_'+contrib).observe('contributions', callback)

        def update():
            """Run the handler on the main thread to avoid GUI issues.

            """
            deferred_call(self._refresh_profiles)

        self._observer = Observer()
        for folder in self._profiles_folders:
            handler = SystematicFileUpdater(update)
            self._observer.schedule(handler, folder, recursive=True)

        self._observer.start() 
开发者ID:Exopy,项目名称:exopy,代码行数:22,代码来源:plugin.py

示例7: wait_on_entry_calc

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def wait_on_entry_calc(self, key):
        with self.lock:
            self._reload_cache()
            entry = self._get_cache()[key]
            if not entry['being_calculated']:
                return entry['value']
        event_handler = _PickleCore.CacheChangeHandler(
            filename=self._cache_fname(), core=self, key=key
        )
        observer = Observer()
        event_handler.inject_observer(observer)
        observer.schedule(
            event_handler, path=self.expended_cache_dir, recursive=True
        )
        observer.start()
        observer.join(timeout=1.0)
        if observer.is_alive():
            # print('Timedout waiting. Starting again...')
            return self.wait_on_entry_calc(key)
        # print("Returned value: {}".format(event_handler.value))
        return event_handler.value 
开发者ID:shaypal5,项目名称:cachier,代码行数:23,代码来源:pickle_core.py

示例8: shell_command

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [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

示例9: _watch

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def _watch(root='.', dest='_site', pattern='**/*.html', exclude='_*/**'):

    try:
        from watchdog.observers import Observer
        from watchdog.events import FileSystemEventHandler
    except ImportError:
        msg = "The build --watch feature requires watchdog. \n"\
            + "Please install it with 'easy_install watchdog'."
        print(msg)
        return None

    class handler(FileSystemEventHandler):
        def on_any_event(self, event):
            exclude_path = os.path.join(os.getcwd(), exclude)
            if not utils.matches_pattern(exclude_path, event.src_path):
                build_files(root=root,
                            dest=dest,
                            pattern=pattern,
                            exclude=exclude)

    observer = Observer()
    observer.schedule(handler(), root, recursive=True)
    observer.start()

    print("Watching '{0}' ...".format(root))

    return observer 
开发者ID:braceio,项目名称:tags,代码行数:29,代码来源:generator.py

示例10: watch

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watch():
    from serapis import tasks
    global tasks_map
    tasks_map = {
        "search": tasks.search,
        "detect": tasks.detect,
        "save": tasks.save
    }

    observer = Observer()
    observer.schedule(TaskHandler(), config.local_s3, recursive=False)
    observer.start()
    print("Watching local bucket in '{}'...".format(config.local_s3))
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join() 
开发者ID:wordnik,项目名称:serapis,代码行数:21,代码来源:lambda_simulator.py

示例11: main

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def main():
    opts = docopt(__doc__, version=__version__)
    environment = Environment.load(opts['ENVIRONMENT'] or '.')
    env_path = environment.target
    less_paths = [
        path_join(env_path, 'ckan', 'ckan', 'public', 'base', 'less'),
        path_join(env_path, 'ckan', 'ckan', 'public', 'base', 'vendor')
    ]

    if not env_path or not all(exists(less_path) for less_path in less_paths):
        print 'No source code to watch found'
        return

    observer = Observer()
    event_handler = LessCompileEventHandler(environment)
    for less_path in less_paths:
        observer.schedule(event_handler, less_path, recursive=True)
    observer.start()

    # HACK: We make it so that the OS doesn't consult us and just kills us.
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    observer.join() 
开发者ID:datacats,项目名称:datacats,代码行数:25,代码来源:lesscd.py

示例12: watch_assets

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watch_assets(options):
    """
    Watch for changes to asset files, and regenerate js/css
    """
    observer = Observer()

    CoffeeScriptWatcher().register(observer)
    SassWatcher().register(observer)
    XModuleSassWatcher().register(observer)

    print("Starting asset watcher...")
    observer.start()
    if not getattr(options, 'background', False):
        # when running as a separate process, the main thread needs to loop
        # in order to allow for shutdown by contrl-c
        try:
            while True:
                observer.join(2)
        except KeyboardInterrupt:
            observer.stop()
        print("\nStopped asset watcher.") 
开发者ID:jruiperezv,项目名称:ANALYSE,代码行数:23,代码来源:assets.py

示例13: run

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def run(self, args):
        self.record_pid()

        # workaround the issue that SIGINT cannot be received (fork a child to
        # avoid blocking the main process in Thread.join()
        child_pid = os.fork()
        if child_pid == 0:  # child
            # observer handles event in a different thread
            observer = Observer()
            observer.schedule(self.event_handler, path=args['image_dir'])
            observer.start()
            self.server()
        else:  # parent
            try:
                os.wait()
            except KeyboardInterrupt:
                os.kill(child_pid, signal.SIGKILL)
                self.erase_pid() 
开发者ID:DT42,项目名称:BerryNet,代码行数:20,代码来源:engineservice.py

示例14: __init__

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def __init__(self, runner):
        self.runner = runner

        self.event_handler = PatternMatchingEventHandler(patterns=["*.fast5"],
                ignore_patterns=[],
                ignore_directories=True)
        self.event_handler.on_created = self.on_created
        self.event_handler.on_moved = self.on_moved

        self.observer = Observer()

        self.observedPaths = []
        for path in self.runner.input:
            if os.path.isdir(path):
                self.observer.schedule(self.event_handler, path, recursive=True)
                self.observedPaths.append(path)
        log("Monitoring {} in real time. Press Ctrl+C to exit.".format(", ".join(self.observedPaths))) 
开发者ID:scottgigante,项目名称:picopore,代码行数:19,代码来源:realtime.py

示例15: Start

# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def Start(self):
        self.Scan(continuous=True)
        self.status.SetLabel("Real-time scanning is running now.")

        if self.observer:
            return
        gisenv = gscript.gisenv()
        mapsetPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'], gisenv['MAPSET'])
        path1 = os.path.join(mapsetPath, 'fcell')
        if not os.path.exists(path1):
            os.mkdir(os.path.join(mapsetPath, 'fcell'))
        path2 = os.path.join(mapsetPath, 'vector')
        if not os.path.exists(path2):
            os.mkdir(os.path.join(mapsetPath, 'vector'))
        paths = [path1, path2]
        handlers = [RasterChangeHandler(self.runImport, self.settings['tangible']['output']),
                    DrawingChangeHandler(self.runImportDrawing, self.settings['tangible']['drawing']['name'])]

        self.observer = Observer()
        for path, handler in zip(paths, handlers):
            self.observer.schedule(handler, path)

        self.observer.start()
        self.timer.Start(1000) 
开发者ID:tangible-landscape,项目名称:grass-tangible-landscape,代码行数:26,代码来源:g.gui.tangible.py


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