本文整理汇总了Python中pulsar.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testBadConfig
def testBadConfig(self):
cfg = Config()
self.assertEqual(cfg.import_from_module('foo/bla/cnkjnckjcn.py'), [])
cfg.set('config', None)
self.assertEqual(cfg.config, None)
cfg = Config(exclude=['config'])
self.assertEqual(cfg.config, None)
开发者ID:cyberj,项目名称:pulsar,代码行数:7,代码来源:config.py
示例2: testSystem
def testSystem(self):
from pulsar import system
cfg = Config()
self.assertEqual(cfg.uid, system.get_uid())
self.assertEqual(cfg.gid, system.get_gid())
self.assertEqual(cfg.proc_name, 'pulsar')
cfg.set('process_name', 'bla')
self.assertEqual(cfg.proc_name, 'bla')
开发者ID:Danzeer,项目名称:pulsar,代码行数:8,代码来源:config.py
示例3: testFunctionFromConfigFile
def testFunctionFromConfigFile(self):
worker = get_actor()
cfg = Config()
self.assertEqual(cfg.worker_task(worker), None)
self.assertTrue(cfg.import_from_module(__file__))
self.assertEqual(cfg.worker_task(worker), worker)
cfg1 = pickle.loads(pickle.dumps(cfg))
self.assertEqual(cfg1.worker_task(worker), worker)
开发者ID:cyberj,项目名称:pulsar,代码行数:8,代码来源:config.py
示例4: __testFunctionFromConfigFile
def __testFunctionFromConfigFile(self):
# TODO, fails in pypy for some odd reasons
worker = get_actor()
cfg = Config()
self.assertEqual(cfg.connection_made(worker), None)
self.assertTrue(cfg.import_from_module(__file__))
self.assertEqual(cfg.connection_made(worker), worker)
cfg1 = pickle.loads(pickle.dumps(cfg))
self.assertEqual(cfg1.connection_made(worker), worker)
开发者ID:Danzeer,项目名称:pulsar,代码行数:9,代码来源:config.py
示例5: testFunction
def testFunction(self):
cfg = Config()
worker = get_actor()
self.assertTrue(cfg.post_fork)
self.assertEqual(cfg.post_fork(worker), None)
cfg.set('post_fork', post_fork)
self.assertEqual(cfg.post_fork(worker), worker)
cfg1 = pickle.loads(pickle.dumps(cfg))
self.assertEqual(cfg1.post_fork(worker), worker)
开发者ID:Danzeer,项目名称:pulsar,代码行数:9,代码来源:config.py
示例6: testFunction
def testFunction(self):
cfg = Config()
worker = get_actor()
self.assertTrue(cfg.arbiter_task)
self.assertEqual(cfg.arbiter_task(worker), None)
cfg.set('arbiter_task', worker_task)
self.assertEqual(cfg.arbiter_task(worker), worker)
cfg1 = pickle.loads(pickle.dumps(cfg))
self.assertEqual(cfg1.arbiter_task(worker), worker)
开发者ID:cyberj,项目名称:pulsar,代码行数:9,代码来源:config.py
示例7: _spawn_actor
def _spawn_actor(cls, monitor, cfg=None, name=None, aid=None, **kw):
# Internal function which spawns a new Actor and return its
# ActorProxyMonitor.
# *cls* is the Actor class
# *monitor* can be either the ariber or a monitor
kind = None
if issubclass(cls, PoolMixin):
kind = 'monitor'
if monitor:
params = monitor.actorparams()
name = params.pop('name', name)
aid = params.pop('aid', aid)
cfg = params.pop('cfg', cfg)
# get config if not available
if cfg is None:
if monitor:
cfg = monitor.cfg.copy()
else:
cfg = Config()
if not monitor: # monitor not available, this is the arbiter
if kind != 'monitor':
raise TypeError('class %s not a valid monitor' % cls)
kind = 'arbiter'
params = {}
if not cfg.exc_id:
if not aid:
aid = gen_unique_id()[:8]
cfg.set('exc_id', aid)
#
for key, value in iteritems(kw):
if key in cfg.settings:
cfg.set(key, value)
else:
params[key] = value
#
if monitor:
if not kind:
if not issubclass(cls, Actor):
raise TypeError('Class %s not a valid actor.' % cls)
kind = cfg.concurrency
if not kind:
raise TypeError('Cannot spawn class %s. not a valid concurrency.'
% cls)
actor_proxy = concurrency(kind, cls, monitor, cfg, name=name,
aid=aid, **params)
# Add to the list of managed actors if this is a remote actor
if isinstance(actor_proxy, Actor):
return actor_proxy
else:
actor_proxy.monitor = monitor
monitor.managed_actors[actor_proxy.aid] = actor_proxy
future = actor_proxy_future(actor_proxy)
actor_proxy.start()
return future
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:56,代码来源:monitor.py
示例8: _spawn_actor
def _spawn_actor(kind, monitor, cfg=None, name=None, aid=None, **kw):
# Internal function which spawns a new Actor and return its
# ActorProxyMonitor.
# *cls* is the Actor class
# *monitor* can be either the arbiter or a monitor
if monitor:
params = monitor.actorparams()
name = params.pop('name', name)
aid = params.pop('aid', aid)
cfg = params.pop('cfg', cfg)
# get config if not available
if cfg is None:
if monitor:
cfg = monitor.cfg.copy()
else:
cfg = Config()
if not aid:
aid = create_aid()
if not monitor: # monitor not available, this is the arbiter
assert kind == 'arbiter'
name = kind
params = {}
if not cfg.exc_id:
cfg.set('exc_id', aid)
#
for key, value in kw.items():
if key in cfg.settings:
cfg.set(key, value)
else:
params[key] = value
#
if monitor:
kind = kind or cfg.concurrency
if not kind:
raise TypeError('Cannot spawn')
maker = concurrency_models.get(kind)
if maker:
c = maker()
return c.make(kind, cfg, name, aid, monitor=monitor, **params)
else:
raise ValueError('Concurrency %s not supported in pulsar' % kind)
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:45,代码来源:concurrency.py
示例9: create_config
def create_config(cls, params, prefix=None, name=None):
"""Create a new :class:`.Config` container.
Invoked during initialisation, it overrides defaults
with ``params`` and apply the ``prefix`` to non global
settings.
"""
if isinstance(cls.cfg, Config):
cfg = cls.cfg.copy(name=name, prefix=prefix)
else:
cfg = cls.cfg.copy()
if name:
cfg[name] = name
if prefix:
cfg[prefix] = prefix
cfg = Config(**cfg)
cfg.update_settings()
cfg.update(params, True)
return cfg
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:19,代码来源:__init__.py
示例10: __call__
def __call__(self, actor=None):
'''Register this application with the (optional) calling ``actor``.
If an ``actor`` is available (either via the function argument or via
the :func:`~pulsar.async.actor.get_actor` function) it must be
:class:`.Arbiter`, otherwise this call is no-op.
If no actor is available, it means this application starts
pulsar engine by creating the :class:`.Arbiter` with its
:ref:`global settings <setting-section-global-server-settings>`
copied to the arbiter :class:`.Config` container.
:return: the ``start`` one time event fired once this application
has fired it.
'''
if actor is None:
actor = get_actor()
monitor = None
if actor and actor.is_arbiter():
monitor = actor.get_actor(self.name)
if monitor is None and (not actor or actor.is_arbiter()):
self.cfg.on_start()
self.logger = self.cfg.configured_logger()
if not actor: # arbiter not available
# This application is starts the arbiter
cfg = Config()
cfg.update(self.arbiter_params())
actor = pulsar.arbiter(cfg=cfg)
self.cfg.set('exc_id', actor.cfg.exc_id)
if self.on_config(actor) is not False:
start = Future(loop=actor._loop)
actor.bind_event('start', partial(self._add_monitor, start))
return start
else:
return
raise ImproperlyConfigured('Already started or not in arbiter domain')
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:36,代码来源:__init__.py
示例11: test_methods
def test_methods(self):
cfg = Config()
self.assertEqual(cfg.get('sdjcbsjkbcd', 'ciao'), 'ciao')
d = dict(cfg.items())
self.assertEqual(len(d), len(cfg))
sett = cfg.get('debug')
self.assertTrue(str(sett))
self.assertEqual(cfg.settings['debug'].default, False)
cfg.set('debug', True, default=True)
self.assertEqual(cfg.debug, True)
self.assertEqual(cfg.settings['debug'].default, True)
开发者ID:Danzeer,项目名称:pulsar,代码行数:11,代码来源:config.py
示例12: remote_get_value
request.actor.logger.info('Setting value')
self.value = value
def remote_get_value(self, request):
request.actor.logger.info('Getting value')
return self.value
def start(arbiter, **kw):
ensure_future(app(arbiter))
async def app(arbiter):
# Spawn a new actor
calc = await Calculator.spawn(name='calc1')
print(calc.name)
# set value in the remote calculator
await calc.set_value(46)
# get value from the remote calculator
value = await calc.get_value()
print(value)
# Stop the application
arbiter.stop()
if __name__ == '__main__':
cfg = Config()
cfg.parse_command_line()
arbiter(cfg=cfg, start=start).start()
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:30,代码来源:remote.py
注:本文中的pulsar.Config类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论