1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
import logging
import os
import psutil
from easyprocess import EasyProcess
from pyvirtualdisplay.util import get_helptext
log = logging.getLogger(__name__)
def prog_check(cmd):
try:
p = EasyProcess(cmd)
p.enable_stdout_log = False
p.enable_stderr_log = False
p.call()
return p.return_code == 0
except Exception:
return False
# def platform_is_osx():
# return sys.platform == "darwin"
def has_displayfd():
return "-displayfd" in get_helptext("Xvfb")
def has_xvnc():
return prog_check(["Xvnc", "-help"])
def worker():
w = 0
PYTEST_XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER")
if PYTEST_XDIST_WORKER:
# gw42
w = int(PYTEST_XDIST_WORKER[2:])
return w
def rfbport():
port = 5900 + worker() + 9876
log.info("rfbport=%s", port)
return port
def kill_process_tree(ep):
parent_pid = ep.pid
parent = psutil.Process(parent_pid)
for child in parent.children(recursive=True):
try:
child.kill()
except psutil.NoSuchProcess:
log.warning("NoSuchProcess error in kill_process_tree")
parent.kill()
|