本文整理汇总了Python中twisted.application.internet.TimerService类的典型用法代码示例。如果您正苦于以下问题:Python TimerService类的具体用法?Python TimerService怎么用?Python TimerService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimerService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: application
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,代码行数:27,代码来源:app.py
示例2: stopService
def stopService(self):
"""
Stop this service. This will release buckets partitions it holds
"""
TimerService.stopService(self)
if self.kz_partition.acquired:
return self.kz_partition.finish()
开发者ID:MariaAbrahms,项目名称:otter,代码行数:7,代码来源:scheduler.py
示例3: __init__
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,代码行数:26,代码来源:zkpartitioner.py
示例4: __init__
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,代码行数:35,代码来源:client.py
示例5: application
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,代码行数:28,代码来源:app.py
示例6: application
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,代码行数:26,代码来源:app.py
示例7: setup_selfheal_service
def setup_selfheal_service(clock, config, dispatcher, health_checker, log):
"""
Setup selfheal timer service and return it.
:param clock: :obj:`IReactorTime` provider
:param dict config: Configuration dict containing selfheal info
:param dispatcher: Effect dispatcher
:param health_checker: ``HealthChecker`` object where SelfHeal's health
check will be added
:param log: :obj:`BoundLog` logger used by service
:return: selfheal service or None if relevant config is not found
:rtype: :obj:`IService`
"""
if "selfheal" not in config:
return None
interval = get_in(["selfheal", "interval"], config, no_default=True)
selfheal = SelfHeal(clock, dispatcher, config_value, interval, log)
func, lock = zk.locked_logged_func(
dispatcher, "/selfheallock", log, "selfheal-lock-acquired",
selfheal.setup)
health_checker.checks["selfheal"] = zk.create_health_check(lock)
sh_timer = TimerService(interval, func)
sh_timer.clock = clock
return sh_timer
开发者ID:rackerlabs,项目名称:otter,代码行数:25,代码来源:api.py
示例8: get_application
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,代码行数:32,代码来源:application.py
示例9: application
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,代码行数:28,代码来源:app.py
示例10: application
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,代码行数:26,代码来源:app.py
示例11: startService
def startService(self):
"""
Start this service. This will start buckets partitioning
"""
self.kz_partition = self.kz_client.SetPartitioner(
self.zk_partition_path, set=set(self.buckets),
time_boundary=self.time_boundary)
TimerService.startService(self)
开发者ID:MariaAbrahms,项目名称:otter,代码行数:8,代码来源:scheduler.py
示例12: __init__
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,代码行数:8,代码来源:_clusterstate.py
示例13: __init__
def __init__(self, poller=None, step=300):
"""
"""
if poller is None:
raise RuntimeError('poller cannot be None')
if not issubclass(type(poller), IPoll):
raise TypeError('poller privided is not a subclass of IPoll')
self._poller = poller
TimerService.__init__(self, step=step, callable=self._poller.poll)
开发者ID:flihp,项目名称:twobit-git-poller,代码行数:9,代码来源:githuborgrepopollerservice.py
示例14: __init__
def __init__(self, poller=None, step=60*5):
""" The magic here is calling the TimerService constructor (old
style class) to set the polling interval and specify the polling
function.
"""
if poller is None:
raise RuntimeError('poller cannot be None')
if not issubclass(type(poller), IPoll):
raise TypeError('poller provided is not a subclass of IPoll');
self._poller = poller
TimerService.__init__(self, step=step, callable=self._poller.poll)
开发者ID:flihp,项目名称:twobit-git-poller,代码行数:11,代码来源:gitpollerservice.py
示例15: __init__
def __init__(self, reactor, interval, k8s, namespace, router):
TimerService.__init__(
self,
interval,
divert_errors_to_log(self._check_once, u"router-update"),
k8s,
namespace,
)
# This attribute controls the the reactor used by TimerService to set
# up the LoopingCall.
self.clock = reactor
self._router = router
开发者ID:LeastAuthority,项目名称:leastauthority.com,代码行数:12,代码来源:_router.py
示例16: StatsGatherer
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,代码行数:53,代码来源:stats.py
示例17: __init__
def __init__(self, all_stations, base_config, base_dir, poll_length, file_pattern,
send_command, command_helper, complete_command, failed_command):
TimerService.__init__(self, poll_length, self.run_poll)
self.log = log
self.all_stations = all_stations
self.base_config = dict(base_config)
self.base_folder = base_dir
self.file_pattern = file_pattern
self.send_command = send_command
self.complete_command = complete_command
self.failed_command = failed_command
self.command_helper = command_helper
开发者ID:leesdolphin,项目名称:eventstreamr,代码行数:12,代码来源:queue.py
示例18: __init__
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,代码行数:51,代码来源:client.py
示例19: __init__
def __init__(self, batchsize, interval, slv_client, clock=None):
"""
Initializes the scheduler service with batch size and interval
:param int batchsize: number of events to fetch on each iteration
:param int interval: time between each iteration
:param slv_client: a :class:`silverberg.client.CQLClient` or
:class:`silverberg.cluster.RoundRobinCassandraCluster` instance used to get lock
:param clock: An instance of IReactorTime provider that defaults to reactor if not provided
"""
from otter.models.cass import LOCK_TABLE_NAME
self.lock = BasicLock(slv_client, LOCK_TABLE_NAME, 'schedule', max_retry=0)
TimerService.__init__(self, interval, self.check_for_events, batchsize)
self.clock = clock
self.log = otter_log.bind(system='otter.scheduler')
开发者ID:sharwell,项目名称:otter,代码行数:15,代码来源:scheduler.py
示例20: test_pickleTimerServiceNotPickleLoopFinished
def test_pickleTimerServiceNotPickleLoopFinished(self):
"""
When pickling L{internet.TimerService}, it won't pickle
L{internet.TimerService._loopFinished}.
"""
# We need a pickleable callable to test pickling TimerService. So we
# can't use self.timer
timer = TimerService(1, fakeTargetFunction)
timer.startService()
dumpedTimer = pickle.dumps(timer)
timer.stopService()
loadedTimer = pickle.loads(dumpedTimer)
nothing = object()
value = getattr(loadedTimer, "_loopFinished", nothing)
self.assertIdentical(nothing, value)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:15,代码来源:test_internet.py
注:本文中的twisted.application.internet.TimerService类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论