Created
January 25, 2019 17:25
-
-
Save TTimo/735cc33f815a7e26c05e6b4ed3ede712 to your computer and use it in GitHub Desktop.
Pyro4 + pulsar
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
#!/usr/bin/env python3 | |
import select | |
import asyncio | |
import pulsar.api | |
import Pyro4 | |
@Pyro4.expose | |
class GreetingMaker(object): | |
def get_fortune(self, name): | |
return "Hello, {0}. Here is your fortune message:\n" \ | |
"Behold the warranty -- the bold print giveth and the fine print taketh away.".format(name) | |
daemon = Pyro4.Daemon() | |
uri = daemon.register(GreetingMaker) | |
ns = Pyro4.locateNS() | |
ns.register('example.greeting', uri) | |
async def main(actor): | |
loop = asyncio.get_event_loop() | |
while True: | |
rs, _, _ = await loop.run_in_executor( | |
None, | |
select.select, | |
daemon.sockets, [], [], 3 | |
) | |
if rs: | |
actor.logger.info('Daemon received a request') | |
daemon.events(rs) | |
def onstart_actor(actor): | |
actor.logger.info('onstart_actor: %r', actor) | |
actor._loop.create_task(main(actor)) | |
def onstart_arbiter(arbiter): | |
arbiter.logger.info('onstart: %r', arbiter) | |
pulsar.api.spawn(start=onstart_actor) | |
if __name__ == '__main__': | |
pulsar.api.arbiter(start=onstart_arbiter).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment