headless rendering

909 views
Skip to first unread message

Andrea Cuttone

unread,
Sep 28, 2015, 3:16:34 PM9/28/15
to pyglet-users
Hello


I am trying to run a hello world pyglet app on OSX 10.10, where I connect through ssh. 
When doing that, I get the following error:

/Users/ancu/pyglet-1.2.3/pyglet/canvas/base.pyc in get_default_screen(self)
     72         :rtype: :class:`Screen`
     73         '''
---> 74         return self.get_screens()[0]
     75
     76     def get_windows(self):

IndexError: list index out of range

which I assume is due to the fact that no Window Manager is running.

I saw that some people suggest to use the virtual X server Xvfb. However even if I have Xvfb running, pyglet seem to not detect it.

Does anyone have experience on how to solve this? 


Best,

Andrea

Andre D

unread,
Sep 28, 2015, 3:40:07 PM9/28/15
to pyglet...@googlegroups.com

Pyglet uses opengl which may not function headlessly either.

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Rob

unread,
Sep 28, 2015, 3:50:30 PM9/28/15
to pyglet-users
Hi,

Can you check what `python -m pyglet.info` returns?

Rob

Op maandag 28 september 2015 21:16:34 UTC+2 schreef Andrea Cuttone:

Andrea Cuttone

unread,
Sep 28, 2015, 4:03:08 PM9/28/15
to pyglet...@googlegroups.com
Hi

here is the output of `python -m pyglet.infoon the server






Andrea Cuttone

--
You received this message because you are subscribed to a topic in the Google Groups "pyglet-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyglet-users/p4Jz4g2QXKs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyglet-users...@googlegroups.com.

Rob

unread,
Sep 28, 2015, 4:12:08 PM9/28/15
to pyglet-users
I guess this answers it:

Sep 28 21:58:49 1.1.1.1 python[14740] <Error>: This user is not allowed access to the window system right now.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.

Not sure if this is something we could fix in pyglet, or whether it is a system config thing.

Rob

Op maandag 28 september 2015 22:03:08 UTC+2 schreef Andrea Cuttone:

Andrea Cuttone

unread,
Sep 28, 2015, 4:15:57 PM9/28/15
to pyglet-users
yes I guess this is the issue, since I am connected with ssh and there is no window manager running. 

So the question is how to make pyglet use a virtual window manager such as Xvfb (which is based on XQuartz)

Tristam MacDonald

unread,
Sep 28, 2015, 4:37:25 PM9/28/15
to pyglet-users
How about remote desktop'ing in, instead of headless SSH?
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.

Andrea Cuttone

unread,
Sep 29, 2015, 9:57:12 AM9/29/15
to pyglet...@googlegroups.com
remote desktop is not a good option in our setup, as it is very slow over VPN, and also we would like to limit the access we give to users to just a terminal.



Andrea Cuttone

Andre D

unread,
Sep 29, 2015, 10:05:36 AM9/29/15
to pyglet...@googlegroups.com

What does the application do with pyglet that a terminal is sufficient?

Andrea Cuttone

unread,
Sep 29, 2015, 10:12:30 AM9/29/15
to pyglet...@googlegroups.com
The application is https://github.com/andrea-cuttone/geoplotlib, a python library for plotting geographical data.
The use case is running the app to render the maps, capture the framebuffer and store it to disk in form of raster images.
This works great when there is a physical screen attached, but it fails with a headless session.





Andrea Cuttone

Andre D

unread,
Sep 29, 2015, 10:13:36 AM9/29/15
to pyglet...@googlegroups.com

Does something like pycairo fit your needs?

Andrea Cuttone

unread,
Sep 29, 2015, 10:20:41 AM9/29/15
to pyglet...@googlegroups.com
the app is already written using pyglet. Wouldn't that require to complete rewrite it using pycairo?



Andrea Cuttone

Tristam MacDonald

unread,
Sep 29, 2015, 11:11:14 AM9/29/15
to pyglet...@googlegroups.com
What are the chances you can switch to a Linux server?

It's likely to be a lot simpler to get X to give you a headless framebuffer (or MESA equivalent), then to rewrite pyglet's OS X implementation to allow headless operation.

Andrea Cuttone

unread,
Sep 29, 2015, 3:51:15 PM9/29/15
to pyglet-users
I now tried on a Ubuntu 13.10 machine

I run xvfb-run ipython hello_world.py:

Traceback (most recent call last):
  File "hello_world.py", line 3, in <module>
    window = pyglet.window.Window()
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/__init__.py", line 357, in __getattr__
    __import__(import_name)
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/window/__init__.py", line 1817, in <module>
    gl._create_shadow_window()
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/window/xlib/__init__.py", line 163, in __init__
    super(XlibWindow, self).__init__(*args, **kwargs)
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/window/__init__.py", line 559, in __init__
    self._create()
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/window/xlib/__init__.py", line 210, in _create
    visual_info = self.config.get_visual_info()
  File "/home/andrea/.local/lib/python2.7/site-packages/pyglet/gl/xlib.py", line 182, in get_visual_info
    self.canvas.display._display, self._fbconfig).contents
ValueError: NULL pointer access

Andrea Cuttone

unread,
Oct 3, 2015, 11:52:34 AM10/3/15
to pyglet-users
All right I finally managed to make it run on Linux:

xvfb-run -s "-screen 0 1400x900x24" python hello_world.py 

This runs without problems on Ubuntu 12.04 and 14.04, and Mint 17.2.

Still no luck on OSX. I guess the problem is that pyglet as most apps in OSX uses Quartz instead of X11, so Xvfb does nothing.

Bleyddyn apRhys

unread,
May 17, 2018, 1:39:32 PM5/17/18
to pyglet-users
I realize this is really old, but I recently ran into a very similar problem and was wondering if you or anyone has found a solution for Mac OS X?

Specifically, I 'm trying to run https://github.com/AppliedDataSciencePartners/WorldModels/blob/master/05_train_controller.py on my iMac. It's not headless, but as soon as my screensaver kicks in I get the same error...

   screen = display.get_default_screen()
 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/canvas/base.py", line 73, in get_default_screen
   return self.get_screens()[0]

IndexError: list index out of range

Accessing the Quartz window system in any non-standard way has always been a problem for OS X, but I had hoped maybe there was a solution by now.

My current work-around is to disable my screensaver, but that also means my computer isn't locked. Not something I care to do, especially given that script could be running for days at a time.

Greg Ewing

unread,
May 18, 2018, 3:25:16 AM5/18/18
to pyglet...@googlegroups.com
Bleyddyn apRhys wrote:
> as soon as my screensaver kicks in I
> get the same error...
>
> screen = display.get_default_screen()
> File
> "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyglet/canvas/base.py",
> line 73, in get_default_screen
> return self.get_screens()[0]
> IndexError: list index out of range

Well, I suppose that kind of makes sense -- your screen can't get
burned in if you don't have one!

--
Greg

Benjamin Moran

unread,
May 18, 2018, 9:38:17 AM5/18/18
to pyglet-users
I wouldn't be surprised if this is a "security feature" of OSX.
Unfortunately I don't have any suggestions for you. I'm curious if it's possible to open other OpenGL applications with a locked screen, or just pyglet. If opening other applications is possible, maybe it's something we can improve in pyglet.

Bleyddyn apRhys

unread,
May 18, 2018, 1:34:54 PM5/18/18
to pyglet-users
I should be able to write an OpenGL Hello World type app in Cocoa and try it out.

I'm also planning on trying to rewrite the script to use python threading instead of MPI. Maybe if the main executable is launched with access to Quartz it will pass that on to all its threads.

Bleyddyn apRhys

unread,
May 23, 2018, 1:16:55 PM5/23/18
to pyglet-users
I found a very similar project https://github.com/duckietown/gym-duckietown that also uses pyglet (and OpenGL, I think) but it runs just fine with my screen locked. So whatever the problem is, it isn't with pyglet. I'm still going through the code to try to figure out what the difference is.

Benjamin Moran

unread,
May 24, 2018, 2:00:57 AM5/24/18
to pyglet-users
Something to check is whether that project is creating new contexts as it runs, or just reusing the same previously created ones.
Reply all
Reply to author
Forward
0 new messages