My script using open AI's gym is leaking memory

Viewed 76

I am trying to make work the openAI's gym on a remote server.

The first problem I had is that I don't have a monitor linked to the server so the env.reset() function was always crashing.

Now I found a workaround on stack overflow, and it seems to work. Here is the code I use:

import gym
from gym import wrappers
from time import time
import matplotlib.pyplot as plt

from pyvirtualdisplay import Display

virtual_display = Display(visible=0, size=(1400, 900))
virtual_display.start()

env = gym.make('CartPole-v1')
env = wrappers.Monitor(env, './videos/' + str(time()) + '/')

# env is created, now we can use it: 
for episode in range(1):
    print(f"episode {episode}") 
    obs = env.reset()
    for step in range(10):
        print(f"step: {step}")
        action = env.action_space.sample()  # or given a custom model, action = policy(observation)
        nobs, reward, done, info = env.step(action)
        if done:
            break

Now my problem is that when I run this script it just keeps increasing the RAM consumption until all my RAM is used and the program stops responding. It is just a cartpole environment so I don't know why it takes that much memory (I think it takes like 20GB just at the env.reset() line!)

Thank you for any help

0 Answers
Related