ponty / PyVirtualDisplay

Python wrapper for Xvfb, Xephyr and Xvnc
BSD 2-Clause "Simplified" License
709 stars 78 forks source link

Unable to specify custom DISPLAY #28

Closed chrisspen closed 6 years ago

chrisspen commented 6 years ago

Perhaps I missed it in the docs and the code, but is there any way to set the DISPLAY value? I'm unable to get this package to work on a headless server, and I'm trying to debug what DISPLAY variable this uses for Xvfb, but there doesn't seem to be any specified in xvfb.py, nor does it seem to allow you to specify one.

All the docs I can find on Xvfb say it should be called like Xvfb :99, but the command generated in XvfbDisplay._cmd doesn't set this variable. Wouldn't that prevent it from working on a headless server?

leviable commented 6 years ago

When I run Display like so:

with Display(visible=False, size=(1000, 1000)):
    # foo

It spawns Xvfb on my headless server like so:

ubuntu:~$ ps -ef | grep -i xvfb
ubuntu   16020 12768  0 14:40 pts/0    00:00:00 Xvfb -br -nolisten tcp -screen 0 1000x1000x24 :1003

And DISPLAY is never set, from what I can see.

How are you creating/using the Display object?

ddofborg commented 6 years ago

I have a related question;

I would like to connect to the framebuffer via a VNC client - what would be a good solution here? Is the DISPLAY :1003 in the example from @levi-rs ?

chrisspen commented 6 years ago

Yes, after digging through the code, I see how the port is auto-generated so as to not conflict with any existing display ports. I guess that answers my question.

My tests are passing/failing nondeterministically on my headless server, whereas they're running perfectly on my localhost. Since all package/OS versions match between the server and my localhost, my next thought was to investigate the only real difference, which was headlessness, and so I wanted to see if the server was not initializing xvfb/xephyr correctly, but it looks like it is.

leviable commented 6 years ago

@chrisspen It's possible that the new virtual display hasn't fully come up yet before you're attempt to use it. See issue #25. I have a some code on my headless machines that waits for xset to return a valid status before proceeding.

chrisspen commented 6 years ago

@levi-rs Maybe. I've tried adding time.sleep() calls and used Selenium's screenshot ability to capture stills, and I'm seeing properly rendered pages but seem to have improperly executed Javascript.

ddofborg commented 6 years ago

@chrisspen Ok, but in some cases you want to run the display on a predefined port and it would be useful to set a predefined port I guess. In my case I want to run a dedicated VNC client to the port, which doesn't help when it's random.

@ponty do you agree? can I make a new request?