Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82213
| Path | csiph.com!usenet.pasdenom.info!aioe.org!newsfeed1.swip.net!news.astraweb.com!border5.a.newsrouter.astraweb.com!not-for-mail |
|---|---|
| From | "Benjamin Risher" <benjamin.risher@1:249/999.remove-cdt-this> |
| To | All |
| Subject | Is cmd.Cmd.cmdloop() integration with asyncio server possible? |
| Message-ID | <54866F2E.1751.complang@piz.noip.com> (permalink) |
| X-Comment-To | All |
| Newsgroups | comp.lang.python |
| X-FTN-AREA | COMP.LANG.PYTHON |
| X-FTN-PID | SoupGate-Win32 v1.05 |
| X-FTN-MSGID | <384bc63e-d9cc-4307-8298-4d9d2aafb851@googlegroups.com> 6490ecdc |
| Content-Type | text/plain; charset=IBM437 |
| Content-Transfer-Encoding | 8bit |
| X-Gateway | piz.noip.com [Synchronet 3.15b-Win32 NewsLink 1.92] |
| X-Server | piz.noip.me |
| Date | 9 Dec 2014 11:32:00 -0500 |
| Lines | 52 |
| Organization | Unlimited download news at news.astraweb.com |
| NNTP-Posting-Host | 2266ad8f.news.astraweb.com |
| X-Trace | DXC=LP`[=a9Aa>e:PIc[8_6SKeL?0kYOcDh@jRScV177L_PaZh[e@ZS;QScl23]GVn`ZmfMHo6fPSBkUk04hIVDTD?[k7g\XjYcGehifPiGS6_2a\m |
| Xref | csiph.com comp.lang.python:82213 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
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
csiph-web