Cannot do rendering with multiprocessing


#1

I tried without multiprocessing and the code worked. But when I tried

for rank in range(num_processes):
    p = mp.Process(target=train, args=(model, params, queue))
    p.start()
    processes.append(p)

I got this error

[2017-07-05 01:59:54,817] Making new env: CartPole-v0
Process Process-1:
Traceback (most recent call last):
  File "/home/bli/anaconda3/lib/python3.6/multiprocessing/process.py", line 249, in _bootstrap
    self.run()
  File "/home/bli/anaconda3/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/bli/github/a3c/training.py", line 19, in train
    last_screen = get_screen(env)
  File "/home/bli/github/a3c/utils.py", line 20, in get_screen
    screen = env.render(mode='rgb_array').transpose(
  File "/home/bli/anaconda3/lib/python3.6/site-packages/gym-0.9.1-py3.6.egg/gym/core.py", line 153, in render
    return self._render(mode=mode, close=close)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/gym-0.9.1-py3.6.egg/gym/envs/classic_control/cartpole.py", line 115, in _render
    self.viewer = rendering.Viewer(screen_width, screen_height)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/gym-0.9.1-py3.6.egg/gym/envs/classic_control/rendering.py", line 51, in __init__
    self.window = pyglet.window.Window(width=width, height=height, display=display)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/window/xlib/__init__.py", line 163, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/window/__init__.py", line 515, in __init__
    context = config.create_context(gl.current_context)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/gl/xlib.py", line 186, in create_context
    return XlibContextARB(self, share)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/gl/xlib.py", line 296, in __init__
    super(XlibContext13, self).__init__(config, share)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/gl/xlib.py", line 199, in __init__
    raise gl.ContextException('Could not create GL context')
pyglet.gl.ContextException: Could not create GL context
[2017-07-05 01:59:54,847] Making new env: CartPole-v0
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 151 requests (151 known processed) with 0 events remaining.

I noticed that it said something about X server. I’m using NVIDIA driver rather than the default X.org X server on Ubuntu.