import IPython
app = IPython.Application.instance()
app.kernel.do_shutdown(True)