def tcp_connect_to_display():
    display_env = os.environ['DISPLAY']
display_host, display_num = display_env.split(':')
display_num_major, display_num_minor = display_num.split('.')
How to determine from a python application if X server/X forwarding is running?