duckietown / gym-duckietown

Self-driving car simulator for the Duckietown universe
http://duckietown.org
Other
51 stars 19 forks source link

Pyglet and multiple processes #38

Closed maximecb closed 6 years ago

maximecb commented 6 years ago

This problem affects nvidia GPUs only. The simulator is currently unable to fork so that multiple processes can be run at the same time. This is somewhat problematic as creating subprocesses is the method used by SubprocVecEnv to create multiple simulators to train with in parallel.

To reproduce:

# Does not crash:
python3 pytorch_rl/main.py --no-vis --env-name Duckie-SimpleSim-Discrete-v0 --algo a2c --num-processes 1

# Crashes
python3 pytorch_rl/main.py --no-vis --env-name Duckie-SimpleSim-Discrete-v0 --algo a2c --num-processes 2

I've opened an issue with Pyglet: https://bitbucket.org/pyglet/pyglet/issues/160/creating-a-new-opengl-context-without-a

A fix has been proposed: https://bitbucket.org/pyglet/pyglet/issues/166/multiprocessing-macos-osx-sierra-python3

The fix would come down to importing Pyglet lazily, after forking. I've experimented a bit and was unable to get this to work previously. It might be possible to completely avoid importing gym_duckietown until after the fork.

maximecb commented 6 years ago

Abdelhakim fixed it. It's a miracle!