# Buggy code
def _init(self):
    policy_params = {"action_noise_std": 0.01}

    env = self.env_creator(self.config["env_config"])
    preprocessor = ModelCatalog.get_preprocessor(self.registry, env)

    self.sess = utils.make_session(single_threaded=False)
    self.policy = policies.GenericPolicy(
        self.registry,
        self.sess,
        env.action_space,
        preprocessor,
        self.config["observation_filter"],
        **policy_params,
    )
    self.optimizer = optimizers.Adam(self.policy, self.config["stepsize"])

    # Create the shared noise table.
    print("Creating shared noise table.")
    noise_id = create_shared_noise.remote(self.config["noise_size"])
    self.noise = SharedNoiseTable(ray.get(noise_id))

    # Create the actors.
    print("Creating actors.")
    self.workers = [
        Worker.remote(
            self.registry, self.config, policy_params, self.env_creator, noise_id
        )
        for _ in range(self.config["num_workers"])
    ]

    self.episodes_so_far = 0
    self.timesteps_so_far = 0
    self.tstart = time.time()


# Traceback (_frozen_importlib._DeadlockError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1720, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/rllib/__init__.py", line 17, in <module>
_register_all()
File "/home/ubuntu/ray/python/ray/rllib/__init__.py", line 14, in _register_all
register_trainable(key, get_agent_class(key))
File "/home/ubuntu/ray/python/ray/rllib/agent.py", line 229, in get_agent_class
from ray.rllib import es
File "/home/ubuntu/ray/python/ray/rllib/es/__init__.py", line 1, in <module>
from ray.rllib.es.es import (ESAgent, DEFAULT_CONFIG)
File "/home/ubuntu/ray/python/ray/rllib/es/es.py", line 19, in <module>
from ray.rllib.es import policies
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 168, in __enter__
File "<frozen importlib._bootstrap>", line 110, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('ray.rllib.es.policies') at 139937598221224

# Fixed code
def _init(self):
    policy_params = {"action_noise_std": 0.01}

    env = self.env_creator(self.config["env_config"])
    from ray.rllib import models

    preprocessor = models.ModelCatalog.get_preprocessor(self.registry, env)

    self.sess = utils.make_session(single_threaded=False)
    self.policy = policies.GenericPolicy(
        self.registry,
        self.sess,
        env.action_space,
        preprocessor,
        self.config["observation_filter"],
        **policy_params,
    )
    self.optimizer = optimizers.Adam(self.policy, self.config["stepsize"])

    # Create the shared noise table.
    print("Creating shared noise table.")
    noise_id = create_shared_noise.remote(self.config["noise_size"])
    self.noise = SharedNoiseTable(ray.get(noise_id))

    # Create the actors.
    print("Creating actors.")
    self.workers = [
        Worker.remote(
            self.registry, self.config, policy_params, self.env_creator, noise_id
        )
        for _ in range(self.config["num_workers"])
    ]

    self.episodes_so_far = 0
    self.timesteps_so_far = 0
    self.tstart = time.time()