Cannot do rendering with multiprocessing


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))

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/", line 249, in _bootstrap
  File "/home/bli/anaconda3/lib/python3.6/multiprocessing/", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/bli/github/a3c/", line 19, in train
    last_screen = get_screen(env)
  File "/home/bli/github/a3c/", 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/", 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/", 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/", 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/", line 163, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/window/", line 515, in __init__
    context = config.create_context(gl.current_context)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/gl/", line 186, in create_context
    return XlibContextARB(self, share)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/gl/", line 296, in __init__
    super(XlibContext13, self).__init__(config, share)
  File "/home/bli/anaconda3/lib/python3.6/site-packages/pyglet/gl/", line 199, in __init__
    raise gl.ContextException('Could not create GL context') 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 server on Ubuntu.