Last active
March 2, 2023 15:02
-
-
Save TTimo/f5c69d1d3011eb2f6422af1ef9dca8cb to your computer and use it in GitHub Desktop.
Pyro4 + asyncio
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 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(): | |
loop = asyncio.get_event_loop() | |
while True: | |
rs, _, _ = await loop.run_in_executor( | |
None, | |
select.select, | |
daemon.sockets, [], [], 3 | |
) | |
if rs: | |
print('Daemon received a request') | |
daemon.events(rs) | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) |
kudos to you I guess .. kinda mind blown that something I posted years ago is getting a response now .. I had to google what Pyro4 was
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you don't need an executor thread at all - you can use
loop.add_reader
: