title: Stop sniffing threads with a KeyboardInterrupt
body: <p>I'm making a Python script that sniffs the network traffic for specific packets. For that, I have several threads. (Let's assume that they are needed.)</p>
  
  <p>I would like to stop these threads when CTRL+C is pressed.</p>
  
  <pre><code>import threading
  from scapy.* import all
  
  class myThread(threading.Thread):
      def __init__(self, protocol):
          threading.Thread.__init__(self)
          self.protocol = protocol
      def run(self):
          my_function(self.protocol)
  
  def callback(packet):
      # Do stuff
  
  def my_function(protocol):
      # Do stuff
      sniff(filter=protocol, prn=callback, store=0)
  
  t1 = myThread("udp")
  t2 = myThread("tcp")
  
  t1.start()
  t2.start()
  
  # magic stuff so that CTRL+C stops the threads
  
  t1.join()
  t2.join()
  
  print("Exiting")
  </code></pre>
  
  <p>How can I achieve that?</p>