Reputation: 1077
WARNING Application instance <Task pending coro=<__call__() running at /home/developer/projects/tabcon/tabcon_env/lib/python3.5/site-packages/channels/http.py:191> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.5/asyncio/futures.py:431, Task._wakeup()]>> for connection <WebRequest at 0x7ffa40e17b00 method=GET uri=/ clientproto=HTTP/1.1> took too long to shut down and was killed.
The above exception occurs and the entire service stops running.
I am using:
Upvotes: 17
Views: 7430
Reputation: 1932
In case anyone is using syncWebsocketConsumer
the syntax is the same as @K.A.'s answer, and resolved my issue as well. Thanks @K.A. for what should be the accepted answer.
Here is the async version of what fixed my issue.
async def disconnect(self, close_code):
print(close_code)
await self.channel_layer.group_discard(
self.room_group_name,
self.channel_name
)
raise StopConsumer()
Upvotes: 0
Reputation: 1659
i got same problem when i try to disconnect the client from client side (by using Postman application ) , and i found the following solution , by raise a StopConsumer() Exception inside websoket disconnect method, kindly have a look at the following official DOCs link https://channels.readthedocs.io/en/stable/topics/consumers.html#closing-consumers
and here is a simple example :
from channels.consumer import SyncConsumer
from channels.exceptions import StopConsumer
class MySyncConsumer(SyncConsumer):
def websocket_connect(self, event):
print('websocket connected1...', event)
self.send({
'type': 'websocket.accept'
})
print('websocket connected2...', event)
def websocket_receive(self, event):
print('websocket recived message...', event)
def websocket_disconnect(self, event):
print('websocket disconnected...', event)
raise StopConsumer()
i don't know if my case same your case but i hope this helpful .
Upvotes: 1