diff options
| author | kobarity | 2026-01-04 22:50:47 +0900 |
|---|---|---|
| committer | Eli Zaretskii | 2026-01-17 18:09:03 +0200 |
| commit | 83b4f1ba26844c178e57ecb93ea8db36e8e6fa89 (patch) | |
| tree | 60328bf46206261c03c4d06524abf34a61fa5d05 /lisp/progmodes/python.el | |
| parent | 83f4e48106a44f1f152bb0ca83b1754fd65ec651 (diff) | |
| download | emacs-83b4f1ba26844c178e57ecb93ea8db36e8e6fa89.tar.gz emacs-83b4f1ba26844c178e57ecb93ea8db36e8e6fa89.zip | |
Performance improvement of 'python-shell-get-process'
'python-shell-get-process' is frequently called from
'python-eldoc--get-doc-at-point' and etc., invoking
'project-current' unless there is a buffer-specific Inferior
Python process. When the buffer is a remote buffer not
belonging to any project and has significant latency,
'project-current' may take a long time. To avoid this,
implement a process cache in 'python-shell-get-process'.
* lisp/progmodes/python.el (python-shell--process-cache)
(python-shell--process-cache-valid): New variables.
(python-shell--invalidate-process-cache): New function.
(python-shell-make-comint): Add a call to the above function.
(python-shell-get-process): Add process cache. (Bug#80045)
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5a820f05d77..848a26229e6 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3816,6 +3816,16 @@ variable. | |||
| 3816 | (compilation-shell-minor-mode 1) | 3816 | (compilation-shell-minor-mode 1) |
| 3817 | (python-pdbtrack-setup-tracking)) | 3817 | (python-pdbtrack-setup-tracking)) |
| 3818 | 3818 | ||
| 3819 | (defvar-local python-shell--process-cache) | ||
| 3820 | (defvar-local python-shell--process-cache-valid) | ||
| 3821 | |||
| 3822 | (defun python-shell--invalidate-process-cache () | ||
| 3823 | "Invalidate process cache." | ||
| 3824 | (dolist (buffer (buffer-list)) | ||
| 3825 | (with-current-buffer buffer | ||
| 3826 | (setq python-shell--process-cache nil | ||
| 3827 | python-shell--process-cache-valid nil)))) | ||
| 3828 | |||
| 3819 | (defun python-shell-make-comint (cmd proc-name &optional show internal) | 3829 | (defun python-shell-make-comint (cmd proc-name &optional show internal) |
| 3820 | "Create a Python shell comint buffer. | 3830 | "Create a Python shell comint buffer. |
| 3821 | CMD is the Python command to be executed and PROC-NAME is the | 3831 | CMD is the Python command to be executed and PROC-NAME is the |
| @@ -3832,6 +3842,7 @@ killed." | |||
| 3832 | (let* ((proc-buffer-name | 3842 | (let* ((proc-buffer-name |
| 3833 | (format (if (not internal) "*%s*" " *%s*") proc-name))) | 3843 | (format (if (not internal) "*%s*" " *%s*") proc-name))) |
| 3834 | (when (not (comint-check-proc proc-buffer-name)) | 3844 | (when (not (comint-check-proc proc-buffer-name)) |
| 3845 | (python-shell--invalidate-process-cache) | ||
| 3835 | (let* ((cmdlist (split-string-and-unquote cmd)) | 3846 | (let* ((cmdlist (split-string-and-unquote cmd)) |
| 3836 | (interpreter (car cmdlist)) | 3847 | (interpreter (car cmdlist)) |
| 3837 | (args (cdr cmdlist)) | 3848 | (args (cdr cmdlist)) |
| @@ -3955,7 +3966,15 @@ If current buffer is in `inferior-python-mode', return it." | |||
| 3955 | 3966 | ||
| 3956 | (defun python-shell-get-process () | 3967 | (defun python-shell-get-process () |
| 3957 | "Return inferior Python process for current buffer." | 3968 | "Return inferior Python process for current buffer." |
| 3958 | (get-buffer-process (python-shell-get-buffer))) | 3969 | (unless (and python-shell--process-cache-valid |
| 3970 | (or (not python-shell--process-cache) | ||
| 3971 | (and (process-live-p python-shell--process-cache) | ||
| 3972 | (buffer-live-p | ||
| 3973 | (process-buffer python-shell--process-cache))))) | ||
| 3974 | (setq python-shell--process-cache | ||
| 3975 | (get-buffer-process (python-shell-get-buffer)) | ||
| 3976 | python-shell--process-cache-valid t)) | ||
| 3977 | python-shell--process-cache) | ||
| 3959 | 3978 | ||
| 3960 | (defun python-shell-get-process-or-error (&optional interactivep) | 3979 | (defun python-shell-get-process-or-error (&optional interactivep) |
| 3961 | "Return inferior Python process for current buffer or signal error. | 3980 | "Return inferior Python process for current buffer or signal error. |