code: def stop(self, timeout=None):
          
          stopped = True
          self.__shutdown.set()
          if self.__bgthread:
              logger.debug('Stopping bgthread')
              self.__bgthread.join(timeout)
              if self.__bgthread.is_alive():
                  logger.warning('bgthread did not finish within timeout')
                  stopped = False
              self.__bgthread = None
          return stopped
docs: Requests device to stop running, waiting at most the given timout in seconds (fractional). Has no effect if
          `run()` was not called with background=True set. Returns True if successfully stopped (or already not running).