code: def local_services(self):
          if not self._loop.inside_loop():
              self._state_lock.acquire()
          try:
              return sorted([(index, name) for index, name in self._name_map.items()], key=lambda element: element[0])
          finally:
              if not self._loop.inside_loop():
                  self._state_lock.release()