view lib/localdisplay.py @ 902:f8c085cfaf72

add angular to laundry/static Ignore-this: dcc246f379a758e22953b9be1f4fd29c darcs-hash:20130831173525-312f9-c7586a9eeba90fd0c99ed9afdf7c9795f1bbc55e
author drewp <drewp@bigasterisk.com>
date Sat, 31 Aug 2013 10:35:25 -0700
parents 2d055bce2e60
children 9155e9a605ec
line wrap: on
line source

import psutil, os

def setDisplayToLocalX():
    """
    set DISPLAY env var in this process to the id of the X process on localhost
    """
    for pid in psutil.get_pid_list():
        try:
            proc = psutil.Process(pid)
            if proc.exe not in ['/usr/bin/Xorg', '/usr/bin/X']:
                continue
        except (psutil.error.AccessDenied, psutil.error.NoSuchProcess):
            continue
        display = proc.cmdline[1]
        assert display.startswith(':'), display
        os.environ['DISPLAY'] = display
        break
    else:
        raise ValueError("didn't find an Xorg process")