Bits & Bytes online Edition

Tips and Tricks

Klaus Reuter, Andreas Schott

Python setuptools

In recent years, the Python programming language has become increasingly popular in the field of scientific computing. On MPCDF systems, a selection of important Python modules is provided, in particular an optimized build of the SciPy stack. The language versions 2.7 and 3.3 are supported.

For Python, a huge number of packages serving virtually any purpose is available on the Internet (see MPCDF users request many of them regularly, however it is often not useful to provide the particular package site-wide. To enable users to easily download, build, and install Python packages, the Python setuptools package was made available recently (modules python27/setuptools and python33/setuptools). Among other functionalities, setuptools provides the command 'easy_install' which can be used to automatically install a certain package together with its dependencies locally as follows:

    easy_install --user PACKAGE_NAME

The Python package is then located at ~/.local and is automatically found by the interpreter.

How to efficiently make use of only one gateway session

Often one has the need for multiple screens with only one putty/ssh session running. In addition, the connection may be unstable and one would loose all the work when getting disconnected. Furthermore, if connected to a machine behind the gateway, this connection would also be lost. The solution to overcome such situations is the command screen. With screen one can open multiple screens in just one session, switch between them and resume them. They survive even if the connection to the gateway gets lost. One just reconnects and resumes the respective sessions.

Here comes, how this can be achieved. Assume one wants a connection to hydra from anywhere in the world, thus one first needs to connect to one of the gateway machines with putty or any other ssh command. After being connected to e.g. gatezero one does not simply invoke ssh hydra but:

    screen -S hydra ssh hydra

The option '-S' is not required, but names the screen session for later identification. The whole will look as if one would be simply connected to hydra via gatezero, but in fact this connection to hydra will survive disconnects from gatezero.

Now assume the session to gatezero is being dropped. After reconnecting to gatezero the command screen -ls will display existing screen sessions, e.g. here something like:

1962.hydra (Attached)

To resume this connection to hydra, returning to where one has been just before the session to gatezero got lost, one has to give the command:

    screen -d -r 1962

The option '-d' is required to drop the existing line from the old session, which seems still to be attached, while the option '-r' will actually resume then this session. May be one needs another session to hydra for editing, then pressing 'Ctrl-a' followed by 'c' will create a new session, leaving the old one attached. Then

    screen -S hydra-editor ssh hydra

will open a new session to hydra. With 'Ctrl-a d' one can detach a session from the display, while the connection behind that session will stay, so one can resume it later.

One can switch between all attached sessions in forward direction with 'Ctrl-a n' (next) and in backward direction with 'Ctrl-a p' (previous). Having multiple screen sessions one can get an overview with the command 'Ctrl-a w'. One can directly switch to one of these sessions with 'Ctlr-a' followed by the number of the session. One can name the session with 'Ctrl-a A'.

There is also the possibility to copy data from one screen to another, or to save the contents of the current screen ('Ctrl-a h' for hardcopy). For more information about screen consult the manpage, which explains also how to configure defaults in ${HOME}/.screenrc.