Skip to content

Instantly share code, notes, and snippets.

@RyanKung
Created September 11, 2017 09:27
Show Gist options
  • Save RyanKung/34a8f28b74e058b05062a7cef102a0e4 to your computer and use it in GitHub Desktop.
Save RyanKung/34a8f28b74e058b05062a7cef102a0e4 to your computer and use it in GitHub Desktop.
Example for pulsar app
from pulsar.apps import Application
from pulsar import arbiter, ensure_future, get_actor, send
class TestApp(Application):
def monitor_start(self, monitor, exc=None):
print('monitor %s start' % monitor.name)
monitor.bind_event('hello_monitor', print)
async def worker_start(self, worker, exc=None):
print('worker %s start' % worker.name)
worker.bind_event('hello_worker', print)
await send(worker.monitor, 'run', self.fire, 'cmd', 'test fire')
def worker_info(self, worker, info=None):
print('worker %s info' % worker.name)
print(worker.get_actor(worker.monitor.aid))
@staticmethod
def fire(monitor, cmd, data, **kw):
monitor.fire_event('hello_monitor', data)
async def main(arbiter, **kw):
app = TestApp(workers=2)
res = ensure_future(app(arbiter))
res.add_done_callback(play_with_monitor)
def play_with_monitor(m):
monitor = get_actor().get_actor('testapp')
assert monitor is not None
monitor.fire_event('hello_monitor', 'hello monitor')
print(monitor.managed_actors)
if __name__ == '__main__':
arbiter(start=main).start()
@kgracki
Copy link

kgracki commented May 28, 2018

Hi. I get error: RuntimeWarning: coroutine 'main' was never awaited hnd(o), but I thought that arbiter method shoud deal with this coroutine. Thanks for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment