code: def _initialize_global_state(self,
                                   redis_address,
                                   redis_password=None,
                                   timeout=20):
          
          self.redis_client = services.create_redis_client(
              redis_address, redis_password)
          start_time = time.time()
  
          num_redis_shards = None
          redis_shard_addresses = []
  
          while time.time() - start_time < timeout:
              # Attempt to get the number of Redis shards.
              num_redis_shards = self.redis_client.get("NumRedisShards")
              if num_redis_shards is None:
                  print("Waiting longer for NumRedisShards to be populated.")
                  time.sleep(1)
                  continue
              num_redis_shards = int(num_redis_shards)
              if num_redis_shards < 1:
                  raise Exception("Expected at least one Redis shard, found "
                                  "{}.".format(num_redis_shards))
  
              # Attempt to get all of the Redis shards.
              redis_shard_addresses = self.redis_client.lrange(
                  "RedisShards", start=0, end=-1)
              if len(redis_shard_addresses) != num_redis_shards:
                  print("Waiting longer for RedisShards to be populated.")
                  time.sleep(1)
                  continue
  
              # If we got here then we successfully got all of the information.
              break
  
          # Check to see if we timed out.
          if time.time() - start_time >= timeout:
              raise Exception("Timed out while attempting to initialize the "
                              "global state. num_redis_shards = {}, "
                              "redis_shard_addresses = {}".format(
                                  num_redis_shards, redis_shard_addresses))
  
          # Get the rest of the information.
          self.redis_clients = []
          for shard_address in redis_shard_addresses:
              self.redis_clients.append(
                  services.create_redis_client(shard_address.decode(),
                                               redis_password))
docs: Initialize the GlobalState object by connecting to Redis.
  
          It's possible that certain keys in Redis may not have been fully
          populated yet. In this case, we will retry this method until they have
          been populated or we exceed a timeout.
  
          Args:
              redis_address: The Redis address to connect.
              redis_password: The password of the redis server.