Skip to content

Commit

Permalink
Merge pull request #4 from kkarrancsu/master
Browse files Browse the repository at this point in the history
Explicitly kill workers when ParallelEnv instance is destroyed
  • Loading branch information
lcswillems committed Aug 21, 2020
2 parents e7fd252 + 64833c6 commit d4212e1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions torch_ac/utils/penv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def worker(conn, env):
elif cmd == "reset":
obs = env.reset()
conn.send(obs)
elif cmd == "kill":
return
else:
raise NotImplementedError

Expand All @@ -34,6 +36,10 @@ def __init__(self, envs):
p.start()
remote.close()

def __del__(self):
for local in self.locals:
local.send(("kill", None))

def reset(self):
for local in self.locals:
local.send(("reset", None))
Expand Down

0 comments on commit d4212e1

Please sign in to comment.