示例#1
0
文件: config.py 项目: cyberj/pulsar
 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)
示例#2
0
 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')
示例#3
0
 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)
示例#4
0
文件: config.py 项目: cyberj/pulsar
 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)
示例#5
0
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
示例#6
0
 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)
示例#7
0
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)
示例#8
0
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)
示例#9
0
 def testBadConfig(self):
     cfg = Config()
     self.assertEqual(cfg.config, 'config.py')
     self.assertEqual(cfg.import_from_module('foo/bla/cnkjnckjcn.py'), [])
     cfg.set('config', None)
     self.assertEqual(cfg.config, None)