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


Python TimerService.setServiceParent方法代码示例

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


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

示例1: __init__

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
    def __init__(self, basedir="."):
        node.Node.__init__(self, basedir)
        self.started_timestamp = time.time()
        self.logSource="Client"
        self.DEFAULT_ENCODING_PARAMETERS = self.DEFAULT_ENCODING_PARAMETERS.copy()
        self.init_introducer_client()
        self.init_stats_provider()
        self.init_secrets()
        self.init_storage()
        self.init_control()
        self.helper = None
        if self.get_config("helper", "enabled", False, boolean=True):
            self.init_helper()
        self._key_generator = KeyGenerator()
        key_gen_furl = self.get_config("client", "key_generator.furl", None)
        if key_gen_furl:
            self.init_key_gen(key_gen_furl)
        self.init_client()
        # ControlServer and Helper are attached after Tub startup
        self.init_ftp_server()
        self.init_sftp_server()

        hotline_file = os.path.join(self.basedir,
                                    self.SUICIDE_PREVENTION_HOTLINE_FILE)
        if os.path.exists(hotline_file):
            age = time.time() - os.stat(hotline_file)[stat.ST_MTIME]
            self.log("hotline file noticed (%ds old), starting timer" % age)
            hotline = TimerService(1.0, self._check_hotline, hotline_file)
            hotline.setServiceParent(self)

        # this needs to happen last, so it can use getServiceNamed() to
        # acquire references to StorageServer and other web-statusable things
        webport = self.get_config("node", "web.port", None)
        if webport:
            self.init_web(webport) # strports string
开发者ID:drewp,项目名称:tahoe-lafs,代码行数:37,代码来源:client.py

示例2: __init__

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
    def __init__(self):
        StatusReceiverMultiService.__init__(self)
        timer = TimerService(60*60, self.report_pending_builds)
        timer.setServiceParent(self)

        timer = TimerService(30, self.metrics)
        timer.setServiceParent(self)
开发者ID:lukemarsden,项目名称:build.labs.clusterhq.com,代码行数:9,代码来源:monitoring.py

示例3: get_application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def get_application(config):
    app = Application('Scrapyd')
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')
    poll_interval = config.getfloat('poll_interval', 5)

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd_mongodb.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(poll_interval, poller.poll)
    webservice = TCPServer(
        http_port, server.Site(Root(config, app)),
        interface=bind_address)

    log.msg('http://%(bind_address)s:%(http_port)s/' % {'bind_address':bind_address, 'http_port':http_port})

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:Tiago-Lira,项目名称:scrapyd-mongodb,代码行数:34,代码来源:application.py

示例4: application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def application(config):
	app = Application("Scrapyd")
	http_port = config.getint('http_port', 6800)
	
	poller = QueuePoller(config)
	eggstorage = FilesystemEggStorage(config)
	scheduler = SpiderScheduler(config)
	environment = Environment(config)
	app.setComponent(IPoller, poller)
	app.setComponent(IEggStorage, eggstorage)
	app.setComponent(ISpiderScheduler, scheduler)
	app.setComponent(IEnvironment, environment)
	
	launcher = Launcher(config, app)
	timer = TimerService(5, poller.poll)
	root = Root(config, app)
	root = configRoot(root, config)
	
	webservice = TCPServer(http_port, server.Site(root))
	log.msg("Scrapyd web console available at http://localhost:%s/" % http_port)

	launcher.setServiceParent(app)
	timer.setServiceParent(app)
	webservice.setServiceParent(app)

	return app
开发者ID:huangpanxx,项目名称:POAS,代码行数:28,代码来源:app.py

示例5: application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def application(config):
	app = Application("Scrapyd")
	http_port = config.getint('http_port', 6800)
	
	portal = Portal(PublicHTMLRealm(config, app), [FilePasswordDB(str(config.get('passwd', '')))])
	credentialFactory = DigestCredentialFactory("md5", "Go away")
	
	poller = QueuePoller(config)
	eggstorage = FilesystemEggStorage(config)
	scheduler = SpiderScheduler(config)
	environment = Environment(config)
	
	app.setComponent(IPoller, poller)
	app.setComponent(IEggStorage, eggstorage)
	app.setComponent(ISpiderScheduler, scheduler)
	app.setComponent(IEnvironment, environment)
	
	launcher = Launcher(config, app)
	timer = TimerService(5, poller.poll)
	webservice = TCPServer(http_port, server.Site(HTTPAuthSessionWrapper(portal, [credentialFactory])))
	log.msg("Scrapyd web console available at http://localhost:%s/" % http_port)
	
	launcher.setServiceParent(app)
	timer.setServiceParent(app)
	webservice.setServiceParent(app)
	
	return app
开发者ID:trunk,项目名称:littlespider,代码行数:29,代码来源:app.py

示例6: application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def application(config):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(5, poller.poll)
    webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
    log.msg("Scrapyd web console available at http://%s:%s/" % (bind_address, http_port))

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:Root-nix,项目名称:scrapy,代码行数:30,代码来源:app.py

示例7: application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def application(config, components=interfaces):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')

    for interface, key in interfaces:
        path = config.get(key)
        cls = load_object(path)
        component = cls(config)
        app.setComponent(interface, component)
    poller = component
        
    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath) 
    launcher = laucls(config, app)

    poll_every = config.getint("poll_every", 5)
    timer = TimerService(poll_every, poller.poll)
    
    webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
    log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
            bind_address=bind_address, http_port=http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:llonchj,项目名称:scrapyd,代码行数:30,代码来源:app.py

示例8: __init__

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
 def __init__(self, kz_client, interval, partitioner_path, buckets,
              time_boundary, log, got_buckets,
              clock=None):
     """
     :param log: a bound log
     :param kz_client: txKazoo client
     :param partitioner_path: ZooKeeper path, used for partitioning
     :param buckets: iterable of buckets to distribute between
         nodes. Ideally there should be at least as many elements as nodes
         taking part in this partitioner. This should be a sequence of str.
     :param time_boundary: time to wait for partitioning to stabilize.
     :param got_buckets: Callable which will be called with a list of
         buckets when buckets have been allocated to this node.
     :param clock: clock to use for checking the buckets on an interval.
     """
     MultiService.__init__(self)
     self.kz_client = kz_client
     self.partitioner_path = partitioner_path
     self.buckets = buckets
     self.log = log
     self.got_buckets = got_buckets
     self.time_boundary = time_boundary
     ts = TimerService(interval, self.check_partition)
     ts.setServiceParent(self)
     ts.clock = clock
     self._old_buckets = []
开发者ID:rackerlabs,项目名称:otter,代码行数:28,代码来源:zkpartitioner.py

示例9: application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def application(config):
    app = Application("Scrapyd")
    http_port = int(environ.get('PORT', config.getint('http_port', 6800)))
    config.cp.set('scrapyd', 'database_url', environ.get('DATABASE_URL'))

    poller = Psycopg2QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = Psycopg2SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    launcher = Launcher(config, app)
    timer = TimerService(5, poller.poll)
    webservice = TCPServer(http_port, server.Site(Root(config, app)))
    log.msg("Scrapyd web console available at http://localhost:%s/ (HEROKU)"
        % http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:kayawaffles,项目名称:scrapy-heroku,代码行数:28,代码来源:app.py

示例10: __init__

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
 def __init__(self, reactor):
     MultiService.__init__(self)
     self._deployment_state = DeploymentState()
     timer = TimerService(1, self._wipe_expired)
     timer.clock = reactor
     timer.setServiceParent(self)
     self._information_wipers = pmap()
     self._clock = reactor
开发者ID:332054781,项目名称:flocker,代码行数:10,代码来源:_clusterstate.py

示例11: StatsGatherer

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
class StatsGatherer(Referenceable, service.MultiService):
    implements(RIStatsGatherer)

    poll_interval = 60

    def __init__(self, basedir):
        service.MultiService.__init__(self)
        self.basedir = basedir

        self.clients = {}
        self.nicknames = {}

        self.timer = TimerService(self.poll_interval, self.poll)
        self.timer.setServiceParent(self)

    def get_tubid(self, rref):
        return rref.getRemoteTubID()

    def remote_provide(self, provider, nickname):
        tubid = self.get_tubid(provider)
        if tubid == '<unauth>':
            print "WARNING: failed to get tubid for %s (%s)" % (provider,
                                                                nickname)
            # don't add to clients to poll (polluting data) don't care about disconnect
            return
        self.clients[tubid] = provider
        self.nicknames[tubid] = nickname

    def poll(self):
        for tubid, client in self.clients.items():
            nickname = self.nicknames.get(tubid)
            d = client.callRemote('get_stats')
            d.addCallbacks(
                self.got_stats,
                self.lost_client,
                callbackArgs=(tubid, nickname),
                errbackArgs=(tubid, ))
            d.addErrback(self.log_client_error, tubid)

    def lost_client(self, f, tubid):
        # this is called lazily, when a get_stats request fails
        del self.clients[tubid]
        del self.nicknames[tubid]
        f.trap(DeadReferenceError)

    def log_client_error(self, f, tubid):
        log.msg(
            "StatsGatherer: error in get_stats(), peerid=%s" % tubid,
            level=log.UNUSUAL,
            failure=f)

    def got_stats(self, stats, tubid, nickname):
        raise NotImplementedError()
开发者ID:p-static,项目名称:tahoe-lafs,代码行数:55,代码来源:stats.py

示例12: __init__

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
    def __init__(self, config, main_tub, control_tub, i2p_provider, tor_provider, introducer_clients,
                 storage_farm_broker):
        """
        Use :func:`allmydata.client.create_client` to instantiate one of these.
        """
        node.Node.__init__(self, config, main_tub, control_tub, i2p_provider, tor_provider)

        self._magic_folders = dict()
        self.started_timestamp = time.time()
        self.logSource = "Client"
        self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()

        self.introducer_clients = introducer_clients
        self.storage_broker = storage_farm_broker

        self.init_stats_provider()
        self.init_secrets()
        self.init_node_key()
        self.init_storage()
        self.init_control()
        self._key_generator = KeyGenerator()
        key_gen_furl = config.get_config("client", "key_generator.furl", None)
        if key_gen_furl:
            log.msg("[client]key_generator.furl= is now ignored, see #2783")
        self.init_client()
        self.load_static_servers()
        self.helper = None
        if config.get_config("helper", "enabled", False, boolean=True):
            if not self._is_tub_listening():
                raise ValueError("config error: helper is enabled, but tub "
                                 "is not listening ('tub.port=' is empty)")
            self.init_helper()
        self.init_ftp_server()
        self.init_sftp_server()
        self.init_magic_folder()

        # If the node sees an exit_trigger file, it will poll every second to see
        # whether the file still exists, and what its mtime is. If the file does not
        # exist or has not been modified for a given timeout, the node will exit.
        exit_trigger_file = config.get_config_path(self.EXIT_TRIGGER_FILE)
        if os.path.exists(exit_trigger_file):
            age = time.time() - os.stat(exit_trigger_file)[stat.ST_MTIME]
            self.log("%s file noticed (%ds old), starting timer" % (self.EXIT_TRIGGER_FILE, age))
            exit_trigger = TimerService(1.0, self._check_exit_trigger, exit_trigger_file)
            exit_trigger.setServiceParent(self)

        # this needs to happen last, so it can use getServiceNamed() to
        # acquire references to StorageServer and other web-statusable things
        webport = config.get_config("node", "web.port", None)
        if webport:
            self.init_web(webport) # strports string
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:53,代码来源:client.py

示例13: application

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
def application(config):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '127.0.0.1')
    poll_interval = config.getfloat('poll_interval', 5)

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(poll_interval, poller.poll)

    webpath = config.get('webroot', 'scrapyd.website.Root')
    webcls = load_object(webpath)

    username = config.get('username', '')
    password = config.get('password', '')
    if username and password:
        if ':' in username:
            sys.exit("The `username` option contains illegal character ':', "
                     "check and update the configuration file of Scrapyd")
        portal = Portal(PublicHTMLRealm(webcls(config, app)),
                        [StringCredentialsChecker(username, password)])
        credential_factory = BasicCredentialFactory("Auth")
        resource = HTTPAuthSessionWrapper(portal, [credential_factory])
        log.msg("Basic authentication enabled")
    else:
        resource = webcls(config, app)
        log.msg("Basic authentication disabled as either `username` or `password` is unset")
    webservice = TCPServer(http_port, server.Site(resource), interface=bind_address)
    log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
            bind_address=bind_address, http_port=http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:scrapy,项目名称:scrapyd,代码行数:50,代码来源:app.py

示例14: __init__

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
    def __init__(self, basedir="."):
        node.Node.__init__(self, basedir)
        # All tub.registerReference must happen *after* we upcall, since
        # that's what does tub.setLocation()
        configutil.validate_config(self.config_fname, self.config,
                                   _valid_config_sections())
        self._magic_folder = None
        self.started_timestamp = time.time()
        self.logSource="Client"
        self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
        self.init_introducer_clients()
        self.init_stats_provider()
        self.init_secrets()
        self.init_node_key()
        self.init_storage()
        self.init_control()
        self._key_generator = KeyGenerator()
        key_gen_furl = self.get_config("client", "key_generator.furl", None)
        if key_gen_furl:
            log.msg("[client]key_generator.furl= is now ignored, see #2783")
        self.init_client()
        self.load_static_servers()
        self.helper = None
        if self.get_config("helper", "enabled", False, boolean=True):
            if not self._tub_is_listening:
                raise ValueError("config error: helper is enabled, but tub "
                                 "is not listening ('tub.port=' is empty)")
            self.init_helper()
        self.init_ftp_server()
        self.init_sftp_server()
        self.init_magic_folder()

        # If the node sees an exit_trigger file, it will poll every second to see
        # whether the file still exists, and what its mtime is. If the file does not
        # exist or has not been modified for a given timeout, the node will exit.
        exit_trigger_file = os.path.join(self.basedir,
                                         self.EXIT_TRIGGER_FILE)
        if os.path.exists(exit_trigger_file):
            age = time.time() - os.stat(exit_trigger_file)[stat.ST_MTIME]
            self.log("%s file noticed (%ds old), starting timer" % (self.EXIT_TRIGGER_FILE, age))
            exit_trigger = TimerService(1.0, self._check_exit_trigger, exit_trigger_file)
            exit_trigger.setServiceParent(self)

        # this needs to happen last, so it can use getServiceNamed() to
        # acquire references to StorageServer and other web-statusable things
        webport = self.get_config("node", "web.port", None)
        if webport:
            self.init_web(webport) # strports string
开发者ID:david415,项目名称:tahoe-lafs,代码行数:50,代码来源:client.py

示例15: execute

# 需要导入模块: from twisted.application.internet import TimerService [as 别名]
# 或者: from twisted.application.internet.TimerService import setServiceParent [as 别名]
    def execute(self):
        log.trace("Executing watcher.")

        self._lastPrintedId = None
        self._lastError = None
        if self.config["interval"]:
            svc = TimerService(self.config["interval"], self.showTimeline)
            svc.setServiceParent(self)

            # Since this runs ~forever, just return a Deferred that doesn't call
            # back.  A swift SIGINT will kill it.
            d = Deferred()

        else:
            # Print it once and exit
            d = self.showTimeline()

        return d
开发者ID:olix0r,项目名称:vtwt,代码行数:20,代码来源:watch.py


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