'Took too long to shut down and was killed

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:

  • channels==2.0
  • channels_redis==2.2.1
  • daphne==2.2.2
  • Django==2.1
  • channels_redis==2.2.1


Solution 1:[1]

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 .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1