view lib/localdisplay.py @ 93:c314196f6164

laundry status display Ignore-this: 2152a4e585894a68a40042849d7200be
author drewp@bigasterisk.com
date Sat, 24 Aug 2013 22:11:55 -0700
parents ef639d892e77
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")