def _worker(remote, parent_remote, env_fn_wrapper, lock=None):
    """
    @brief      Worker for each subprocess of SubprocVecEnvLock.

    @details    It enables the use of a threading.Lock. It is the only
                difference with the implementation provided with the
                class `SubprocVecEnv` of Gym OpenAI.

    @remark     `remote` and `parent_remote` are returned by the method `Pipe` of
                `multiprocessing`.  It is a pair of connection objects connected
                by a pipe which by default is duplex (two-way). See
                `multiprocessing` documentation for more information.

                This is a hidden function that is not automatically imported
                using 'from gym_jiminy import *'.

    @param[in]  remote              Child remote
    @param[in]  parent_remote       Parent remote
    @param[in]  env_fn_wrapper      Gym environment
    @param[in]  lock                threading.Lock object. Optional: None by default
    """
    parent_remote.close()
    env = env_fn_wrapper.var()
    while True:
        try:
            cmd, data = remote.recv()
            if cmd == 'step':
                observation, reward, done, info = env.step(data)
                if done:
                    info['terminal_observation'] = observation
                    observation = env.reset()
                remote.send((observation, reward, done, info))
            elif cmd == 'reset':
                observation = env.reset()
                remote.send(observation)
            elif cmd == 'render':
                remote.send(env.render(*data[0], lock=lock, **data[1]))
            elif cmd == 'close':
                remote.close()
                break
            elif cmd == 'get_spaces':
                remote.send((env.observation_space, env.action_space))
            elif cmd == 'env_method':
                method = getattr(env, data[0])
                remote.send(method(*data[1], **data[2]))
            elif cmd == 'get_attr':
                remote.send(getattr(env, data))
            elif cmd == 'set_attr':
                remote.send(setattr(env, data[0], data[1]))
            else:
                raise NotImplementedError
        except EOFError:
            break
