def restart_kernel(self, now=False, **kw):
if self._launch_args is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>if self.has_kernel:<EOL><INDENT>if now:<EOL><INDENT>self.kill_kernel()<EOL><DEDENT>else:<EOL><INDENT>self.shutdown_kernel(restart=True)<EOL><DEDENT><DEDENT>self._launch_args.update(kw)<EOL>self.start_kernel(**self._launch_args)<EOL>if sys.platform == '<STR_LIT:win32>':<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL><DEDENT><DEDENT>
Restarts a kernel with the arguments that were used to launch it.

        If the old kernel was launched with random ports, the same ports will be
        used for the new kernel.

        Parameters
        ----------
        now : bool, optional
            If True, the kernel is forcefully restarted *immediately*, without
            having a chance to do any cleanup action.  Otherwise the kernel is
            given 1s to clean up before a forceful restart is issued.

            In all cases the kernel is restarted, the only difference is whether
            it is given a chance to perform a clean shutdown or not.

        **kw : optional
            Any options specified here will replace those used to launch the
            kernel.