I'd recommend copying the elegant way ipython notebook shutsdown when you press crtl+C