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

John Burkhart jfburkhart.reg@gmail....
Mon Jul 9 13:08:20 CDT 2012

Frank, you might be interested in this recipe, but i haven't had success 
so far with Ipython... but it would be great!


=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:

nohup myjob.sh > nohup_output.nh

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:
    echo "export DISPLAY=$DISPLAY" > .display.`whoami`.`hostname`

2 Again, on your ''host'' machine,make sure the following is in your 
    ## set the prompt command to read the .disply file
    export PROMPT_COMMAND=". ~/.display.`whoami`.`hostname`"

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 

More information about the IPython-User mailing list