docstr: Expect some sub-envs to fail (and not recover), but re-create worker.
docstr_tok: ["Expect","some","sub-envs","to","fail","(","and","not","recover",")",",","but","re-create","worker","."]
code: def test_crash_only_one_worker_during_sampling_but_recreate(self):
      """Expect some sub-envs to fail (and not recover), but re-create worker."""
      config = (
          PGConfig()
          .rollouts(
              env_runner_cls=ForwardHealthCheckToEnvWorker,
              num_rollout_workers=2,
              rollout_fragment_length=10,
              num_envs_per_worker=3,
              # Re-create failed workers (then continue).
              recreate_failed_workers=True,
          )
          .training(train_batch_size=60)
          .environment(
              env=CartPoleCrashing,
              env_config={
                  "crash_after_n_steps": 10,
                  # Crash prob=100%, so test is deterministic.
                  "p_crash": 1.0,
                  # Only crash on worker with index 2.
                  "crash_on_worker_indices": [2],
                  # Make sure nothing happens during pre-checks.
                  "skip_env_checking": True,
              },
          )
      )
      # Pre-checking disables, so building the Algorithm is save.
      algo = config.build()
      # Try to re-create for infinite amount of times.
      # The worker recreation/ignore tolerance used to be hard-coded to 3, but this
      # has now been
      for _ in range(10):
          # Expect some errors being logged here, but in general, should continue
          # as we recover from all worker failures.
          algo.train()
          # One worker has been removed.
          self.assertEqual(algo.workers.num_healthy_remote_workers(), 1)
      algo.stop()
  
file_path: ray/python/ray/rllib/evaluation/tests/test_envs_that_crash.py
imports: import unittest
  import ray
  from ray.rllib.algorithms.pg import PGConfig
  from ray.rllib.algorithms.ppo import PPOConfig
  from ray.rllib.algorithms.tests.test_worker_failures import ForwardHealthCheckToEnvWorker
  from ray.rllib.examples.env.cartpole_crashing import CartPoleCrashing
  from ray.rllib.utils.error import EnvError
label_desc: Use image node_id 6 for calling the TestEnvsThatCrash obj's underlying member method code with example usage: obj.test_crash_only_one_worker_during_sampling_but_recreate() without return types