Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gnu screen trick to launch ipython notebook within screen session non interactively
#!/bin/sh
# set -x
# set -e
sessionname=ipython-notebook
if screen -list | grep $sessionname ; then
echo "Screen session $sessionname is already running."
echo "not doing anything"
else
echo "Starting iPython notenbook in screen session '$sessionname'"
# A bit of explanation:
# -dm: start screen in "detached" mode
# -S: give the session a name
# bash -c 'source ....': launch a bash shell and source virtual enviroment settings before launching ipython
# Now, pick one of the following options:
### Use standard/system wide iPython notebook
screen -dm -S $sessionname ipython notebook
### Use iPython from a virtualenv.
# screen -dm -S $sessionname bash -c 'source virtualenv/bin/activate; ipython notebook'
### Use iPython form Anaconda environment
# screen -dm -S $sessionname bash -c 'source activate ipython2; ipython notebook'
echo "iPython Notebook should be running now, have fun!"
fi
echo "Reattach to the screen session (e.g. to shut down) with:"
echo " screen -r $sessionname"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.