I am again with the same problem. In all tank were under my control, and I could manually close them. But the trouble is: I needed webcakes here. In the examples in any correct closure, it is not produced:
start_server = websockets.Serv (Hello, 'Localhost' , 8765 ) asyncio.get_event_loop (). Run_Until_complete (StA rt_server) asyncio.get_event_loop (). Run_Forever () I Played with examples, and yes, with Ctrl+C, it swores if there is a connected client:
$ Python WebSocket_SERVER.PY ^ckeyboardinterrupTexception ignored in : Task Was Destroyed BUT IT IS PENTASK: & LT; TASK Pending Coro = & Lt; Run () Running at websockets/Protocol.py: 235 & gt; Wait_for = & Lt; Future Pending CB = [Task._wakeup ()] & gt; cb = [_ wait. & lt; locals & gt; ._ on_complement () AT Asyncio/Tasks.py: 399 ] & gt; task was destroyed but it is pending! task: & lt; Task pending Coro = & lt; get () running at asyncio/queues.py: 198 & gt; Wait_for = & Lt; Future Pending CB = [Task._wakeup ()] & gt; cb = [_ wait. & lt; locals & gt; ._ on_complement () AT Asyncio/Tasks.py: 399 ] & gt; task was destroyed but it is pending! task: & lt; Task pending Coro = & Lt; Handler () Running at websockets/server.py: 64 & gt; Wait_for = & Lt; Future Pending CB = [Task._wakeup ()] & gt; & gt; since the correct completion in the documentation is not presented and rapidly pumping all kinds server.close () did not lead to any productive result, the question of the correct completion of the application arises again, if the tusks are not controlled by me.
This is just this library of the curve? Or is it typical for any asyncio-bibliotek and I don’t understand something in the very essence of asyncio and someone flows me and some kind of mattress about this?
how to correctly complete the whole case?
with the general case, but websokockets are not to close in no way wants. The minimum example for repetition (based on the @jfs response):
#!/Usr/bin/env python3 #-*-coding: utf-8-*- import asyncio import websockts @asyncio.coroutine def echo ws, path ) Class = ""> Print ( 'Client Started' ) white true : data = yield from ws.recv () if data> is no : : : : : : break yield from ws.Send (data) print ( 'Client Finined' ) loop = asyncio.get_event_loop () start_server = websockets.Serv (echo, '' 127.0.1 ' span>, 8888 , look = look) server = loop.ru_Until_complete (start_server) print ( 'listen' ) try : server = loop.ru_forever () pass server.close () loop.ru_Until_complete (server.wait_closed ()) loop.close () print ( 'fined' ) just connect any client to it (at least from the browser & mdash; & nbsp; ws = New WebSocket ('WS: //127.0.1: 8888/');
) and press Ctrl+C & Mdash; & Nbsp; The previously given error is printed (though without keyboardinterrapt).
question@mail.ru
·