Skip to content

Commit 06373a6

Browse files
committed
ob-python: Fix Emacs bug#50514 when Python loads slowly
* lisp/ob-python.el (org-babel-python-initiate-session-by-key): Do not rely on 10ms delay to initialize Python. Wait until python process is initialized using `org-babel-comint-wait-for-output'.
1 parent 5ba90e1 commit 06373a6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lisp/ob-python.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ then create. Return the initialized session."
197197
(setq py-buffer (org-babel-python-with-earmuffs session)))
198198
(let ((python-shell-buffer-name
199199
(org-babel-python-without-earmuffs py-buffer)))
200-
(run-python cmd)
201-
(sleep-for 0 10)))
200+
(run-python cmd)))
202201
((and (eq 'python-mode org-babel-python-mode)
203202
(fboundp 'py-shell)) ; python-mode.el
204203
(require 'python-mode)
@@ -217,6 +216,8 @@ then create. Return the initialized session."
217216
(py-shell nil nil t org-babel-python-command py-buffer nil nil t nil)))
218217
(t
219218
(error "No function available for running an inferior Python")))
219+
;; Wait until Python initializes.
220+
(org-babel-comint-wait-for-output py-buffer)
220221
(setq org-babel-python-buffers
221222
(cons (cons session py-buffer)
222223
(assq-delete-all session org-babel-python-buffers)))

0 commit comments

Comments
 (0)