Function: python-shell-restart

python-shell-restart is an interactive and byte-compiled function defined in python.el.gz.

Signature

(python-shell-restart &optional SHOW)

Documentation

Restart the Python shell.

Optional argument SHOW (interactively, the prefix argument), if non-nil, means also display the Python shell buffer.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-shell-restart (&optional show)
  "Restart the Python shell.
Optional argument SHOW (interactively, the prefix argument), if
non-nil, means also display the Python shell buffer."
  (interactive "P")
  (with-current-buffer
      (or (and (derived-mode-p 'inferior-python-mode)
               (current-buffer))
          (seq-some (lambda (dedicated)
                      (get-buffer (format "*%s*" (python-shell-get-process-name
                                                  dedicated))))
                    '(buffer project nil))
          (user-error "No Python shell"))
    (when-let* ((proc (get-buffer-process (current-buffer))))
      (kill-process proc)
      (while (accept-process-output proc)))
    (python-shell-make-comint (python-shell-calculate-command)
                              (string-trim (buffer-name) "\\*" "\\*")
                              show)))