shariqiqbal2810 / MAAC

Code for "Actor-Attention-Critic for Multi-Agent Reinforcement Learning" ICML 2019
MIT License
666 stars 172 forks source link

VecEnv, why closing the Pipe() #11

Closed GoingMyWay closed 5 years ago

GoingMyWay commented 5 years ago

Hi, in the code

class SubprocVecEnv(VecEnv):
    def __init__(self, env_fns, spaces=None):
        """
        envs: list of gym environments to run in subprocesses
        """
        self.waiting = False
        self.closed = False
        nenvs = len(env_fns)
        self.remotes, self.work_remotes = zip(*[Pipe() for _ in range(nenvs)])
        self.ps = [Process(target=worker, args=(work_remote, remote, CloudpickleWrapper(env_fn)))
            for (work_remote, remote, env_fn) in zip(self.work_remotes, self.remotes, env_fns)]
        for p in self.ps:
            p.daemon = True # if the main process crashes, we should not cause things to hang
            p.start()
        for remote in self.work_remotes:
            remote.close()

Why

        for remote in self.work_remotes:
            remote.close()

if the remote pipe is closed, how the message be sent?

shariqiqbal2810 commented 5 years ago

I didn't write this code originally (I modified it from OpenAI baselines), so to be honest, I do not know. I believe it has to do with the fact that closing the work remotes in the main process does not close them in the worker process. So when the main process sends something via remotes it gets received by the worker process via worker_remotes and vice versa.

GoingMyWay commented 5 years ago

@shariqiqbal2810 Thank you. I think it is true.