Executing X-Windows app

Randall Hopper aa8vb at yahoo.com
Mon Jan 24 11:41:42 EST 2000


Jamey Cribbs:
 |
 |Hi, I hope this doesn't end up being a stupid question.  I am trying to
 |start a n X app from within a Python script.
 |
 |If I use os.system, my system freezes until I CTRL-C.  If I run os.system
 |from interactive Python, it works ok.  I have tried popen, but it does
 |the same thin g.
 |
 |What am I missing?  I am sure it is something very basic.  I have looked
 |throug ht the ref manual, but cannot seem to find the answer.  By the
 |way, I am running on top of RH Linux 6.1 with Python 1.52.  Any help
 |would be greatly appreciated.

Two things: 

   1) the X app needs to know which X display to use, and 
   2) the app needs to have permission to write to that X display.

1) So first, which display. The X display to be used is typically
   identified by the $DISPLAY environment variable (or the -display
   command-line option, as an override).

   Make sure the display is being set correctly.  For example:

        >>> os.system( "xclock -display ralph:0.0" )
   OR:
        >>> os.system( "env DISPLAY=ralph:0.0 xclock" )

2) Second, make sure this app has "permission" to write to that display.
   If it's running as a user which has a cookie for that display, and it is
   running on a machine where that cookie resides, then it does.  Or, if
   the (insecure) xhost utility has been used to open up access to the
   display to the app's host, then it does.

   For more info on magic cookies, see xauth(1); the cookies typically
   live in ~/.Xauthority.  For more info on xhost, see xhost(1).

   If your hosts are isolated from the world by a firewall, then for
   testing you can just run:
    
        xhost +

   on the X display host to open display access wide up to everyone and
   his brother, including your app.  This is very insecure!, so I wouldn't
   use it long term.

So why does the command line work?  When you start Python from the
command-line, $DISPLAY is already set, so Python (and it's subprocesses,
like your X app).  Just inherit that setting.  Also, your X terminal shell
has permission to write to your display (usually via a magic cookie), and
python and it's children inherit that too (assuming the children run as the
same user).

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list