#NEWLINE# def restart_kernel( self , now = False , **kw ) : #NEWLINE# #INDENT# 'Restarts a kernel with the arguments that were used to launch it.\n        \n        If the old kernel was launched with random ports, the same ports will be\n        used for the new kernel.\n\n        Parameters\n        ----------\n        now : bool, optional\n            If True, the kernel is forcefully restarted *immediately*, without\n            having a chance to do any cleanup action.  Otherwise the kernel is\n            given 1s to clean up before a forceful restart is issued.\n\n            In all cases the kernel is restarted, the only difference is whether\n            it is given a chance to perform a clean shutdown or not.\n\n        **kw : optional\n            Any options specified here will replace those used to launch the\n            kernel.\n        ' #NEWLINE# if ( self . _launch_args is None ) : #NEWLINE# #INDENT# raise RuntimeError ( "Cannot restart the kernel. No previous call to 'start_kernel'." ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . has_kernel : #NEWLINE# #INDENT# if now : #NEWLINE# #INDENT# self . kill_kernel ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . shutdown_kernel ( restart = True ) #NEWLINE# #UNINDENT# #UNINDENT# self . _launch_args . update ( kw ) #NEWLINE# self . start_kernel ( ** self . _launch_args ) #NEWLINE# if ( sys . platform == 'win32' ) : #NEWLINE# #INDENT# time . sleep ( 0.2 )