ponty / PyVirtualDisplay

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

How to use existing display / set display number? #97

Open plonknimbuzz opened 4 days ago

plonknimbuzz commented 4 days ago

Hi, there

i have this service:

#/etc/systemd/system/xvfb.service

[Unit]
Description=X virtual framebuffer

[Service]
Type=simple
User=root

ExecStart=/usr/bin/Xvfb :99 -ac

[Install]
WantedBy=multi-user.target
ps -ef|grep Xvfb
root     15802     1  0 Jul28 ?        00:00:00 /usr/bin/Xvfb :99 -ac

as u can see that i used :99 as display number but i failed to set it using this script

from pyvirtualdisplay import Display
import os
print(os.environ.get("DISPLAY"))
os.environ["DISPLAY"] = ":99"
print(os.environ.get("DISPLAY"))
with Display() as disp:
    # display is active
    print(disp.is_alive()) # True
    print(os.environ.get("DISPLAY"))
# display is stopped
print(disp.is_alive())

result

None
:99
True
:0 ==> failed
False

my question is: how to set display number? because i want to use display that created from outside of this library

plonknimbuzz commented 4 days ago

or, if there is no available method for my case. at least, how can i find my previous display?

something like this

def run(action):
    disp = Display() #idk how to attach old display
    if(disp.is_alive):
        if(action=='start'):
            print('continue existing display')
            return disp
        else:
            disp.stop()
            print('stop existing display')
            return None
    else:
        if(action=='start'):
            print('create new display')
            return disp #return something that i can use 1 hour later
        else:
            print('display not found. Cannot stop the display')
            return None
The-Compiler commented 4 days ago

What's the point? The whole idea behind this library is starting and managing an Xvfb process. If you already have one, there's nothing left for it to do?