Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82213 > unrolled thread
| Started by | "Benjamin Risher" <benjamin.risher@1:249/999.remove-cdt-this> |
|---|---|
| First post | 2014-12-09 11:32 -0500 |
| Last post | 2014-12-09 11:32 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Is cmd.Cmd.cmdloop() integration with asyncio server possible? "Benjamin Risher" <benjamin.risher@1:249/999.remove-cdt-this> - 2014-12-09 11:32 -0500
| From | "Benjamin Risher" <benjamin.risher@1:249/999.remove-cdt-this> |
|---|---|
| Date | 2014-12-09 11:32 -0500 |
| Subject | Is cmd.Cmd.cmdloop() integration with asyncio server possible? |
| Message-ID | <54866F2E.1751.complang@piz.noip.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.
--- SoupGate-Win32 v1.05
* Origin: <SpaceSST.BBS.Fidonet<>NNTP.gateway.@.piz.noip.me> (1:249/999)
--- Synchronet 3.15b-Win32 NewsLink 1.92
SpaceSST BBS Usenet <> Fidonet Gateway
Back to top | Article view | comp.lang.python
csiph-web