Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_color_xvfb():
with pytest.raises(XStartError):
vd = Display(color_depth=99).start().stop()
vd = Display(color_depth=16).start().stop()
vd = Display(color_depth=24).start().stop()
vd = Display(color_depth=8).start().stop()
def test_stop_nostart():
with pytest.raises(XStartError):
Display().stop()
def stop(self):
"""
stop display
:rtype: self
"""
if not self._is_started:
raise XStartError("stop() is called before start().")
self._redirect_display(False)
if self.is_alive():
try:
try:
self._subproc.terminate()
except AttributeError:
os.kill(self._subproc.pid, signal.SIGKILL)
except OSError as oserror:
log.debug("exception in terminate:%s", oserror)
self._subproc.wait()
self._read_stdout_stderr()
if self._use_xauth:
self._clear_xauth()
def start(self):
"""
start display
:rtype: self
"""
if self._is_started:
raise XStartError(self, "Display was started twice.")
self._is_started = True
if self._has_displayfd:
self._start1()
else:
i = 0
while True:
try:
self._start1()
break
except XStartError:
log.warning("start failed %s", i + 1)
time.sleep(0.05)
i += 1
if i >= self._retries:
raise XStartError(
def _wait_for_pipe_text(self, rfd):
s = ""
start_time = time.time()
while True:
(rfd_changed_ls, _, _) = select.select([rfd], [], [], 0.1)
if not self.is_alive():
raise XStartError(
"%s program closed. command: %s stderr: %s"
% (self._program, self._command, self.stderr)
)
if rfd in rfd_changed_ls:
c = os.read(rfd, 1)
if c == b"\n":
break
s += c.decode("ascii")
if time.time() - start_time >= _X_START_TIMEOUT:
raise XStartTimeoutError(
"No reply from program %s. command:%s"
% (self._program, self._command,)
)
return s
:rtype: self
"""
if self._is_started:
raise XStartError(self, "Display was started twice.")
self._is_started = True
if self._has_displayfd:
self._start1()
else:
i = 0
while True:
try:
self._start1()
break
except XStartError:
log.warning("start failed %s", i + 1)
time.sleep(0.05)
i += 1
if i >= self._retries:
raise XStartError(
"No success after %s retries. Last stderr: %s"
% (self._retries, self.stderr)
)
finally:
self._redirect_display(False)
self._redirect_display(True)
break
if exit_code != 0:
pass
else:
log.info('Successfully started X with display "%s".', d)
ok = True
break
if time.time() - start_time >= _X_START_TIMEOUT:
break
time.sleep(_X_START_TIME_STEP)
if not self.is_alive():
log.warning("process exited early. stderr:%s", self.stderr)
msg = "Failed to start process: %s"
raise XStartError(msg % self)
if not ok:
msg = 'Failed to start X on display "%s" (xdpyinfo check failed, stderr:[%s]).'
raise XStartTimeoutError(msg % (d, xdpyinfo.stderr))
return self