コード例 #1
0
 def __call__(self, a=None):
     if a is None:
         a = yield spawn(name='greeter')
     if names:
         name = names.pop()
         send(a, 'greetme', {'name': name})
         self._loop.call_later(1, self, a)
     else:
         arbiter().stop()
コード例 #2
0
def spawn_actor_from_actor(actor, name):
    actor2 = yield from spawn(name=name)
    pong = yield from send(actor2, 'ping')
    assert pong == 'pong', 'no pong from actor'
    t1 = time()
    # cover the notify from a fron actor
    t2 = yield from send(actor2, 'notify', {})
    assert t2 >= t1

    return actor2.aid
コード例 #3
0
ファイル: utils.py プロジェクト: cyberj/pulsar
 def spawn(self, concurrency=None, **kwargs):
     concurrency = concurrency or self.concurrency
     ad = pulsar.spawn(concurrency=concurrency, **kwargs)
     self.assertTrue(ad.aid)
     self.assertTrue(isinstance(ad, pulsar.ActorProxyDeferred))
     yield ad
     self.a = ad.result
     self.all_spawned.append(self.a)
     self.assertEqual(self.a.aid, ad.aid)
     self.assertTrue(self.a.address)
コード例 #4
0
 def __call__(self, a=None):
     if a is None:
         a = yield from pulsar.spawn(name='greeter')
     if names:
         name = names.pop()
         self._loop.logger.info("Hi! I'm %s" % name)
         yield from pulsar.send(a, 'greetme', {'name': name})
         self._loop.call_later(1, pulsar. async, self(a))
     else:
         pulsar.arbiter().stop()
コード例 #5
0
ファイル: greeter.py プロジェクト: Danzeer/pulsar
 def __call__(self, a=None):
     if a is None:
         a = yield from pulsar.spawn(name='greeter')
     if names:
         name = names.pop()
         self._loop.logger.info("Hi! I'm %s" % name)
         yield from pulsar.send(a, 'greetme', {'name': name})
         self._loop.call_later(1, pulsar.async, self(a))
     else:
         pulsar.arbiter().stop()
コード例 #6
0
ファイル: arbiter.py プロジェクト: JinsongBian/pulsar
 def test_spawning_in_arbiter(self):
     arbiter = pulsar.get_actor()
     self.assertEqual(arbiter.name, 'arbiter')
     self.assertTrue(len(arbiter.monitors) >= 1)
     name = 'testSpawning-%s' % self.concurrency
     future = spawn(name=name, concurrency=self.concurrency)
     self.assertTrue(future.aid in arbiter.managed_actors)
     proxy = yield future
     self.assertEqual(future.aid, proxy.aid)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     yield send(proxy, 'stop')
コード例 #7
0
ファイル: utils.py プロジェクト: huobao36/pulsar
 def spawn_actor(self, concurrency=None, **kwargs):
     '''Spawn a new actor and perform some tests.'''
     concurrency = concurrency or self.concurrency
     ad = pulsar.spawn(concurrency=concurrency, **kwargs)
     self.assertTrue(ad.aid)
     self.assertTrue(isinstance(ad, ActorProxyFuture))
     proxy = yield ad
     self.all_spawned.append(proxy)
     self.assertEqual(proxy.aid, ad.aid)
     self.assertEqual(proxy.proxy, proxy)
     self.assertTrue(proxy.cfg)
     coroutine_return(proxy)
コード例 #8
0
 def test_spawning_in_arbiter(self):
     arbiter = pulsar.get_actor()
     self.assertEqual(arbiter.name, 'arbiter')
     self.assertTrue(len(arbiter.monitors) >= 1)
     name = 'testSpawning-%s' % self.concurrency
     future = spawn(name=name, concurrency=self.concurrency)
     self.assertTrue(future.aid in arbiter.managed_actors)
     yield future
     proxy = future.result
     self.assertEqual(future.aid, proxy.aid)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     yield send(proxy, 'stop')
コード例 #9
0
ファイル: utils.py プロジェクト: robgil/pulsar
 def spawn_actor(self, concurrency=None, **kwargs):
     '''Spawn a new actor and perform some tests
     '''
     concurrency = concurrency or self.concurrency
     ad = pulsar.spawn(concurrency=concurrency, **kwargs)
     self.assertTrue(ad.aid)
     self.assertTrue(isinstance(ad, ActorProxyFuture))
     proxy = yield ad
     self.all_spawned.append(proxy)
     self.assertEqual(proxy.aid, ad.aid)
     self.assertEqual(proxy.proxy, proxy)
     self.assertTrue(proxy.cfg)
     coroutine_return(proxy)
コード例 #10
0
ファイル: utils.py プロジェクト: devopsmi/pulsar
 async def spawn_actor(self, concurrency=None, **kwargs):
     '''Spawn a new actor and perform some tests
     '''
     concurrency = concurrency or self.concurrency
     ad = pulsar.spawn(concurrency=concurrency, **kwargs)
     self.assertTrue(ad.aid)
     self.assertIsInstance(ad, asyncio.Future)
     proxy = await ad
     self.all_spawned.append(proxy)
     self.assertEqual(proxy.aid, ad.aid)
     self.assertEqual(proxy.proxy, proxy)
     self.assertTrue(proxy.cfg)
     return proxy
コード例 #11
0
 def spawn(self, concurrency=None, **kwargs):
     '''Spawn a new actor and perform some tests.'''
     concurrency = concurrency or self.concurrency
     ad = pulsar.spawn(concurrency=concurrency, **kwargs)
     self.assertTrue(ad.aid)
     self.assertTrue(isinstance(ad, pulsar.ActorProxyDeferred))
     yield ad
     proxy = ad.result
     self.all_spawned.append(proxy)
     self.assertEqual(proxy.aid, ad.aid)
     self.assertEqual(proxy.proxy, proxy)
     self.assertTrue(proxy.cfg)
     yield proxy
コード例 #12
0
ファイル: utils.py プロジェクト: arhik/pulsar
 def spawn_actor(self, concurrency=None, **kwargs):
     '''Spawn a new actor and perform some tests
     '''
     concurrency = concurrency or self.concurrency
     ad = pulsar.spawn(concurrency=concurrency, **kwargs)
     self.assertTrue(ad.aid)
     self.assertIsInstance(ad, asyncio.Future)
     proxy = yield from ad
     self.all_spawned.append(proxy)
     self.assertEqual(proxy.aid, ad.aid)
     self.assertEqual(proxy.proxy, proxy)
     self.assertTrue(proxy.cfg)
     return proxy
コード例 #13
0
ファイル: arbiter.py プロジェクト: cyberj/pulsar
 def testSpawning(self):
     arbiter = pulsar.get_actor()
     self.assertEqual(arbiter.name, 'arbiter')
     self.assertTrue(len(arbiter.monitors) >= 1)
     future = spawn(name='testSpawning', concurrency=self.concurrency)
     self.assertTrue(future.aid in arbiter.spawning_actors)
     self.assertFalse(future.aid in arbiter.managed_actors)
     yield future
     proxy = future.result
     self.assertEqual(future.aid, proxy.aid)
     self.assertFalse(future.aid in arbiter.spawning_actors)
     self.assertEqual(proxy.name, 'testSpawning')
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     yield send(proxy, 'stop')
コード例 #14
0
def app(arbiter):
    # Spawn a new actor
    proxy = yield from spawn(name='actor1')
    print(proxy.name)
    # Execute inner method in actor1
    result = yield from send(proxy, 'run', inner_method)
    print(result)

    yield from send(proxy, 'run', set_value, 10)
    value = yield from send(proxy, 'run', get_value)
    print(value)

    # Stop the application
    arbiter.stop()
コード例 #15
0
 def test_spawning_in_arbiter(self):
     arbiter = pulsar.get_actor()
     self.assertEqual(arbiter.name, 'arbiter')
     self.assertTrue(len(arbiter.monitors) >= 1)
     name = 'testSpawning-%s' % self.concurrency
     future = spawn(name=name, concurrency=self.concurrency)
     self.assertTrue(future.aid in arbiter.managed_actors)
     proxy = yield future
     self.assertEqual(future.aid, proxy.aid)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     self.assertEqual(proxy, arbiter.get_actor(proxy.aid))
     #
     # Stop the actor
     result = yield send(proxy, 'stop')
     self.assertEqual(result, None)
     #
     result = yield wait_for_stop(self, proxy.aid)
     self.assertEqual(result, None)
コード例 #16
0
 def test_spawning_in_arbiter(self):
     arbiter = pulsar.get_actor()
     self.assertEqual(arbiter.name, 'arbiter')
     self.assertTrue(len(arbiter.monitors) >= 1)
     name = 'testSpawning-%s' % self.concurrency
     future = spawn(name=name, concurrency=self.concurrency)
     self.assertTrue(future.aid in arbiter.managed_actors)
     proxy = yield from future
     self.assertEqual(future.aid, proxy.aid)
     self.assertEqual(proxy.name, name)
     self.assertTrue(proxy.aid in arbiter.managed_actors)
     self.assertEqual(proxy, arbiter.get_actor(proxy.aid))
     #
     yield from asyncio.sleep(1)
     # Stop the actor
     result = yield from send(proxy, 'stop')
     self.assertEqual(result, None)
     #
     result = yield from wait_for_stop(self, proxy.aid)
     self.assertEqual(result, None)
コード例 #17
0
ファイル: hooks.py プロジェクト: pombredanne/minilab
from functools import partial
from pulsar import spawn, TcpServer

import pulsar


def create_echo_server(address, actor):
    '''Starts an echo server on a newly spawn actor'''
    server = TcpServer(actor.event_loop, address[0], address[1],
                       EchoServerProtocol)
    yield server.start_serving()
    actor.servers['echo'] = server
    actor.extra['echo-address'] = server.address


arbiter = pulsar.arbiter()
proxy = spawn(start=partial(create_echo_server, 'localhost:9898'))
コード例 #18
0
ファイル: api.py プロジェクト: robgil/pulsar
 def test_bad_concurrency(self):
     # bla concurrency does not exists
     actor = yield pulsar.spawn(kind='bla')
     self.assertFalse(actor)
コード例 #19
0
def async(fn):
    def task_wrapper(actor, *args, **kwargs):
        return fn(*args, **kwargs)
    fn.async = lambda *k, **kw: pulsar.spawn(start=partial(task_wrapper, *k, **kw))
    return fn
コード例 #20
0
def period_task(fn):
    def task_wrapper(actor):
        return fn()
    if pulsar.get_actor():
        pulsar.spawn(period_task=task_wrapper)
    return fn
コード例 #21
0
# -*- coding: utf-8 -*-
from pulsar import spawn

import pulsar
import random


class PeriodicTask:
    def __call__(self, actor):
        actor.event_loop.call_repeatedly(2, self.task)

    def task(self):
        print(random.randint(0, 9))


arbiter = pulsar.arbiter()

ap = spawn(start=PeriodicTask())
コード例 #22
0
ファイル: hooks.py プロジェクト: xmnlab/minilab
from functools import partial
from pulsar import spawn, TcpServer

import pulsar

def create_echo_server(address, actor):
    '''Starts an echo server on a newly spawn actor'''
    server = TcpServer(actor.event_loop, address[0], address[1],
                       EchoServerProtocol)
    yield server.start_serving()
    actor.servers['echo'] = server
    actor.extra['echo-address'] = server.address

arbiter = pulsar.arbiter()
proxy = spawn(start=partial(create_echo_server, 'localhost:9898'))
コード例 #23
0
 def spawn(cls, **kwargs):
     proxy = yield from spawn(**kwargs)
     return cls(proxy)
コード例 #24
0
def actor1(request, message):
    act2 = yield from spawn(name='actor2')
    r = send(act2, 'actor2', dict(message="Important data"))
    r.add_done_callback(lambda resolved_promise: print(resolved_promise))
    return "Message sent"
コード例 #25
0
 def test_bad_concurrency(self):
     # bla concurrency does not exists
     actor = yield pulsar.spawn(kind="bla")
     self.assertFalse(actor)
コード例 #26
0
ファイル: quick_start.py プロジェクト: xmnlab/minilab
# -*- coding: utf-8 -*-
from pulsar import spawn

import pulsar
import random

class PeriodicTask:
    def __call__(self, actor):
        actor.event_loop.call_repeatedly(2, self.task)

    def task(self):
        print(random.randint(0, 9))

arbiter = pulsar.arbiter()

ap = spawn(start=PeriodicTask())
コード例 #27
0
 def __call__(self, a=None):
     act1 = yield from spawn(name='actor1')
     r = send(act1, 'actor1', dict(data=[1, 2, 4]))
     r.add_done_callback(
         lambda resolved_promise: print(resolved_promise.result()))
     arbiter().stop()