title: Using django channels with threading.Thead
body: <p>I'm using django channels in order to send multiple responses to a single request. The code is something like this:</p>
  
  <pre><code>class terminal(WebsocketConsumer):
     def connect(self):
         self.accept()
  
     def disconnect(self, close_code):
         self.close()
  
     def receive(self, text_data):
         data_json = json.loads(text_data)
         if data_json['event'] == 'initial':
            self.t = threading.Thread(target=self.send_data)
            self.t.daemon = True
            self.t.start()
         elif data_json['event'] == 'pause':
            pass
         print("done")
  
     def send_data(self):
         n = 100
         end = 1000000
         while (n + 1 &lt; end)
            # some code
            self.send(json.dumps({'data':data})
            n += 1
  </code></pre>
  
  <p>I've used thread to be able to listen to <strong><em>pause</em></strong> and other events while data is being sent to the client. 
  The problem is that the thread keeps running after websocket gets disconnected. </p>
  
  <p>Is there a way to kill a python thread in <strong><em>disconnect</em></strong> function? Or maybe a better way to implement this?</p>