code: def _service_task(self):  # pragma: no cover
          
          while True:
              if len(self.sockets) == 0:
                  # nothing to do
                  self.sleep(self.ping_timeout)
                  continue
  
              # go through the entire client list in a ping interval cycle
              sleep_interval = self.ping_timeout / len(self.sockets)
  
              try:
                  # iterate over the current clients
                  for s in self.sockets.copy().values():
                      if not s.closing and not s.closed:
                          s.check_ping_timeout()
                      self.sleep(sleep_interval)
              except (SystemExit, KeyboardInterrupt):
                  self.logger.info('service task canceled')
                  break
              except:
                  # an unexpected exception has occurred, log it and continue
                  self.logger.exception('service task exception')
docs: Monitor connected clients and clean up those that time out.