code: def stop_listener_thread(self):
          
          # when stopping, `kill` will cause the `self.api.sync` call in _sync
          # to raise a connection error. This flag will ensure it exits gracefully then
          self.should_listen = False
          if self.sync_thread:
              self.sync_thread.kill()
              self.sync_thread.get()
          if self._handle_thread is not None:
              self._handle_thread.get()
          self.sync_thread = None
          self._handle_thread = None
docs: Kills sync_thread greenlet before joining it