Created
September 11, 2017 09:27
-
-
Save RyanKung/34a8f28b74e058b05062a7cef102a0e4 to your computer and use it in GitHub Desktop.
Example for pulsar app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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