本文整理汇总了Python中twisted.application.service.Service方法的典型用法代码示例。如果您正苦于以下问题:Python service.Service方法的具体用法?Python service.Service怎么用?Python service.Service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.application.service
的用法示例。
在下文中一共展示了service.Service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: privilegedStartService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def privilegedStartService(self):
"""
Start listening on the endpoint.
"""
service.Service.privilegedStartService(self)
self._waitingForPort = self.endpoint.listen(self.factory)
raisedNow = []
def handleIt(err):
if self._raiseSynchronously:
raisedNow.append(err)
elif not err.check(CancelledError):
log.err(err)
self._waitingForPort.addErrback(handleIt)
if raisedNow:
raisedNow[0].raiseException()
self._raiseSynchronously = False
示例2: test_everythingThere
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def test_everythingThere(self):
"""
L{twisted.application.internet} dynamically defines a set of
L{service.Service} subclasses that in general have corresponding
reactor.listenXXX or reactor.connectXXX calls.
"""
trans = 'TCP UNIX SSL UDP UNIXDatagram Multicast'.split()
for tran in trans[:]:
if not getattr(interfaces, "IReactor" + tran)(reactor, None):
trans.remove(tran)
for tran in trans:
for side in 'Server Client'.split():
if tran == "Multicast" and side == "Client":
continue
if tran == "UDP" and side == "Client":
continue
self.assertTrue(hasattr(internet, tran + side))
method = getattr(internet, tran + side).method
prefix = {'Server': 'listen', 'Client': 'connect'}[side]
self.assertTrue(hasattr(reactor, prefix + method) or
(prefix == "connect" and method == "UDP"))
o = getattr(internet, tran + side)()
self.assertEqual(service.IService(o), o)
示例3: test_service_factory
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def test_service_factory(self):
"""
``VolumeScript._create_volume_service`` uses
``VolumeScript._service_factory`` to create a ``VolumeService`` (or
whatever else that hook decides to create).
"""
expected = Service()
script = VolumeScript(object())
self.patch(
VolumeScript, "_service_factory",
staticmethod(lambda config_path, pool, reactor: expected))
options = VolumeOptions()
options.parseOptions([])
service = script._create_volume_service(
object(), object(), options)
self.assertIs(expected, service)
示例4: test_main_deferred_fires_after_service_stop
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def test_main_deferred_fires_after_service_stop(self):
"""
The ``Deferred`` returned by ``AgentScript.main`` doesn't fire
until after the ``Deferred`` returned by the ``stopService`` method of
the service created by ``service_factory``.
"""
shutdown_deferred = Deferred()
class SlowShutdown(Service):
def stopService(self):
return shutdown_deferred
service = SlowShutdown()
agent = AgentScript(
service_factory=lambda reactor, options: service
)
stop_deferred = agent.main(self.reactor, self.options)
self.reactor.fireSystemEvent("shutdown")
self.assertNoResult(stop_deferred)
shutdown_deferred.callback(None)
self.assertIs(None, self.successResultOf(stop_deferred))
示例5: assertErrorWritten
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def assertErrorWritten(self, raised, reported):
"""
Assert L{UnixApplicationRunner.postApplication} writes
C{reported} to its status pipe if the service raises an
exception whose message is C{raised}.
"""
class FakeService(service.Service):
def startService(self):
raise RuntimeError(raised)
errorService = FakeService()
errorService.setServiceParent(self.runner.application)
with AlternateReactor(FakeDaemonizingReactor()):
self.assertRaises(RuntimeError, self.runner.postApplication)
self.assertEqual(
self.mockos.actions,
[('chdir', '.'), ('umask', 0o077), ('fork', True), 'setsid',
('fork', True), ('write', -2, reported),
('unlink', 'twistd.pid')])
self.assertEqual(self.mockos.closed, [-3, -2])
示例6: startService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def startService(self):
service.Service.startService(self)
factory = redis.SubscriberFactory()
factory.protocol = MasterProtocol
factory.continueTrying = True
factory.db = self.db
yield self.db.startService()
yield reactor.connectTCP(config.REDIS_HOST, config.REDIS_PORT, factory)
self.rc = yield factory.deferred
yield self.rc.subscribe(self.channel)
log.info('Subscribed to {channel}', channel=self.channel)
self.lc = LoopingCall(self.checkNoData)
self.nodata_check = self.lc.start(config.NODATA_CHECK_INTERVAL, now=True)
示例7: __init__
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def __init__(self, basedir):
service.Service.__init__(self)
self._basedir = basedir
示例8: startService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def startService(self):
self.log.info('Starting Soledad Service')
self._container = SoledadContainer(service=self)
super(SoledadService, self).startService()
# hooks
示例9: _hook_on_passphrase_entry
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def _hook_on_passphrase_entry(self, provider, **kw):
if is_service_ready('mx', provider):
userid = kw.get('username')
password = kw.get('password')
uuid = kw.get('uuid')
container = self._container
self.log.debug('On_passphrase_entry: '
'New Soledad Instance: %s' % userid)
if not container.get_instance(userid):
container.add_instance(userid, password, uuid=uuid, token=None)
else:
self.log.debug('Service MX is not ready...')
示例10: stopService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def stopService(self):
self.log.info('Stopping IMAP Service')
if self._port:
self._port.stopListening()
self._port = None
if self._factory:
self._factory.doStop()
super(IMAPService, self).stopService()
示例11: startInstance
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def startInstance(self, userid):
"""returns: a deferred"""
self._set_status(userid, "starting")
soledad = self._mail.get_soledad_session(userid)
keymanager = self._mail.get_keymanager_session(userid)
self.log.info('Setting up Incoming Mail Service for %s' % userid)
return self._start_incoming_mail_instance(
keymanager, soledad, userid)
示例12: startService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def startService(self):
zf = ZmqFactory()
e = ZmqEndpoint(ZmqEndpointType.bind, ENDPOINT)
self._conn = _DispatcherREPConnection(zf, e, self._core)
reactor.callWhenRunning(self._conn.do_greet)
service.Service.startService(self)
示例13: stopService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def stopService(self):
service.Service.stopService(self)
示例14: setupService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def setupService(self):
self.log(log.info, u'Bootstrapping')
self.settings = self.parent.settings
# Optionally register subsystem component as child service
for subsystem in self.subsystems:
if hasattr(self, subsystem):
subsystem_service = getattr(self, subsystem)
if isinstance(subsystem_service, Service):
log.info('Registering subsystem component "{subsystem}" as service', subsystem=subsystem)
self.registerService(subsystem_service)
# Configure metrics to be collected each X seconds
metrics_interval = int(self.channel.get('metrics_logger_interval', 60))
self.metrics = Bunch(tx_count=0, starttime=time.time(), interval=metrics_interval)
subscriptions = read_list(self.channel.mqtt_topics)
self.mqtt_service = MqttAdapter(
name = u'mqtt-' + self.channel.realm,
broker_host = self.settings.mqtt.host,
broker_port = int(self.settings.mqtt.port),
broker_username = self.settings.mqtt.username,
broker_password = self.settings.mqtt.password,
callback = self.mqtt_receive,
subscriptions = subscriptions)
self.registerService(self.mqtt_service)
self.influx = InfluxDBAdapter(settings = self.settings.influxdb)
# Perform MQTT message processing using a different thread pool
self.threadpool = ThreadPool()
self.thimble = Thimble(reactor, self.threadpool, self, ["process_message"])
示例15: __getstate__
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import Service [as 别名]
def __getstate__(self):
d = service.Service.__getstate__(self)
for attr in self.volatile:
if attr in d:
del d[attr]
return d