Fix bug:
https://bugs.launchpad.net/ipython/+bug/269966
This fixes a long-standing and serious problem with long-running IPython
sessions. Finally!
Many thanks to John D. Hunter and Sameer D'Costa for the feedback,
especially for Sameer's patch that finally put me on the right track for a
clean solution.