import IPython IPython.Application.instance().kernel.do_shutdown(True) #automatically restarts kernel