Skip to content

Commit 526e586

Browse files
author
BoboTiG
committed
MSSLinux: early detect DISPLAY to stop before all operations
1 parent d713a3f commit 526e586

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

mss.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ def __del__(self):
303303
def __init__(self):
304304
''' GNU/Linux initialisations '''
305305

306+
disp = None
307+
self.display = None
308+
try:
309+
if sys.version > '3':
310+
disp = bytes(environ['DISPLAY'], 'utf-8')
311+
else:
312+
disp = environ['DISPLAY']
313+
except KeyError:
314+
err = 'MSS: $DISPLAY not set. Stopping to prevent segfault.'
315+
raise ScreenshotError(err)
316+
306317
x11 = find_library('X11')
307318
if not x11:
308319
raise ScreenshotError('MSS: no X11 library found.')
@@ -316,17 +327,6 @@ def __init__(self):
316327
self._set_argtypes()
317328
self._set_restypes()
318329

319-
disp = None
320-
self.display = None
321-
try:
322-
if sys.version > '3':
323-
disp = bytes(environ['DISPLAY'], 'utf-8')
324-
else:
325-
disp = environ['DISPLAY']
326-
except KeyError:
327-
err = 'MSS: $DISPLAY not set. Stopping to prevent segfault.'
328-
raise ScreenshotError(err)
329-
330330
# At this point, if there is no running server, it could end on
331331
# a segmentation fault. And we cannot catch it.
332332
self.display = self.xlib.XOpenDisplay(disp)

0 commit comments

Comments
 (0)