code: def listen(self, timeout=10):
          
          self._socket.settimeout(float(timeout))
          while not self.stopped.isSet():
              try:
                  data, client_address = self._socket.recvfrom(4096)
              except socket.timeout:
                  continue
              try:
                  #Start a new thread not to block other requests
                  args = ((data, client_address), )
                  t = threading.Thread(target=self.receive_datagram, args=args)
                  t.daemon = True
                  t.start()
              except RuntimeError:
                  logging.exception("Exception with Executor")
          logging.debug("closing socket")
          self._socket.close()
docs: Listen for incoming messages. Timeout is used to check if the server must be switched off.
  
          :param timeout: Socket Timeout in seconds