Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82134 > unrolled thread
| Started by | Benjamin Risher <brisher777@gmail.com> |
|---|---|
| First post | 2014-12-08 10:27 -0800 |
| Last post | 2014-12-08 10:27 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Is cmd.Cmd.cmdloop() integration with asyncio server possible? Benjamin Risher <brisher777@gmail.com> - 2014-12-08 10:27 -0800
| From | Benjamin Risher <brisher777@gmail.com> |
|---|---|
| Date | 2014-12-08 10:27 -0800 |
| Subject | Is cmd.Cmd.cmdloop() integration with asyncio server possible? |
| Message-ID | <384bc63e-d9cc-4307-8298-4d9d2aafb851@googlegroups.com> |
I'm working on an asyncio server project. I'd also like to have a cmd.Cmd style command loop interface for spawning instances of the server. As far as I've seen, running an asyncio server requires
...
loop.run_forever()
...
And cmd.Cmd.cmdloop() is a blocking loop, so I'm not able to call them sequentially. Is there a way to get the cmdloop to run asynchronously? Or a way to call asyncio.streams.start_server from the cmdloop and actually have it run continuously? I've tried a few things but nothing has been successful. I should mention that by itself, the server functions.
For brevity, I'll try to keep the code to what is relevant.
class MyServer:
...
def start():
server = asyncio.async(
asyncio.streams.start_server(
self.accept_client,
host=self.ip,
port=self.port,
loop=self.loop
)
)
return server
...
class MyMenu(cmd.Cmd):
def __init__(self, loop):
cmd.Cmd.__init__(self)
...
do_serve(self, **kwargs):
server = MyServer(self.loop, **kwargs)
instance = server.start()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
menu = MyMenu(loop)
menu.cmdloop()
Calling loop.run_forever() at any point breaks the menu functionality. Any help would be greatly appreciated.
Back to top | Article view | comp.lang.python
csiph-web