ponty / PyVirtualDisplay

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

KeyError when env doesn't have a DISPLAY #2

Closed Hornswoggles closed 13 years ago

Hornswoggles commented 13 years ago

xephyr=Display(visible=1, size=(320, 240)).start() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.6/dist-packages/pyvirtualdisplay/abstractdisplay.py", line 65, in start self.old_display_var = os.environ['DISPLAY'] File "/usr/lib/python2.6/UserDict.py", line 22, in __getitem__ raise KeyError(key) KeyError: 'DISPLAY'

Easily fixed by adding DISPLAY to the environment with $: export DISPLAY=':0'

Could handle the exception with a message or needs some logic to handle if DISPLAY doesn't exist. How about:

-        self.old_display_var = os.environ['DISPLAY']
+         self.old_display_var = os.environ['DISPLAY'] if 'DISPLAY' in os.environ else ':0'
ponty commented 13 years ago

Code is updated: ae5fb6f

I don't understand, why there is no DISPLAY variable. What is your use case?

Hornswoggles commented 13 years ago

A base ubuntu install without x-server doesn't have a DISPLAY var set. So after manually installing Xvfb, Xephyr and pyvirtualdisplay I encountered this Key Error.