[IPython-User] DISPLAY environment in IPython/matplotlib running in screen(1)?

John Burkhart jfburkhart.reg@gmail....
Sun Jul 15 02:45:42 CDT 2012

Hello everyone,

Just wanted to follow up on this thread because I found a great solution 

There is a program called xpra which creates a virtual monitor (x 
server) to which you can point your DISPLAY variable.

You can start a screen session with the DISPLAY setting pointing to this 
virtual display. Then when you run Ipython (inside screen) anything sent 
to X-display is sent to the virtual environment. You can attach and 
detach to this environment and your GUIs / matplotlib windows, etc will 
remain alive.

To install xpra:

sudo apt-get install xpra

Then a session:

#First, start a screen session pointing to a virtual display
xpra start :100
DISPLAY=:100 screen
#now inside screen

#In another terminal, attach to the xpra display to 'see' the X programs
xpra attach :100

You can detach from both these sessions, and they'll keep running, get 
home or wherever... reattach to screen and also reattach to your xpra 
virtual display.


On 07/09/2012 08:08 PM, John Burkhart wrote:
> Frank, you might be interested in this recipe, but i haven't had success
> so far with Ipython... but it would be great!
> --john
> =A trick for working with SSH, and screen=
> Often you'll want to ssh to a server, start a job and leave. Knowing
> that you want the job to stay alive after you log out, you can just use:
> <pre>
> nohup myjob.sh > nohup_output.nh
> </pre>
> But sometimes you'd rather have an actual term or shell session stay
> alive. This is often the case when working with ipython. The problem is
> that your $DISPLAY environment variable may change, so that when you log
> into the machine later, what screen thinks is the present $DISPLAY
> variable will no longer be current and you'll get errors.
> My workaround for this has been the following:
> 1 On the ''host'' machine, that is the one you are logging into, in your
> <code>.bash_profile </code> (which gets read when you log in via ssh)
> you should add the line:
>    <pre>
>     echo "export DISPLAY=$DISPLAY" > .display.`whoami`.`hostname`
>    </pre>
> 2 Again, on your ''host'' machine,make sure the following is in your
> .bashrc:
>    <pre>
>     ## set the prompt command to read the .disply file
>     export PROMPT_COMMAND=". ~/.display.`whoami`.`hostname`"
>    </pre>
> What is happening here is that everytime you log in, the .bash_profile
> file creates a new file in your home directory, specific to your user,
> and the hostname. Whenever you log out and log back in, that file is
> updated with the appropriate DISPLAY information. In the .bashrc file,
> we've created a PROMPT_COMMAND that will read that file everytime you
> hit return in your shell. This can cause some annoyances if the file
> does not exist, for example if you use the 'su' command to become
> another user. However, overall it works quite well, such that when you
> return to a running ''screen'' session, the DISPLAY variable will be
> updated and you'll be able to send X-display windows back to your client
> machine.

More information about the IPython-User mailing list