GNU bug report logs -
#50514
28.0.50; org inline call to python src block req C-g to break
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On Aug 27, 2022, at 6:30 PM, Ihor Radchenko <yantar92 <at> gmail.com<mailto:yantar92 <at> gmail.com>> wrote:
* 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'.
---
lisp/ob-python.el | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 932aca08e..e50a7c2e2 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -197,8 +197,7 @@ (defun org-babel-python-initiate-session-by-key (&optional session)
(setq py-buffer (org-babel-python-with-earmuffs session)))
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs py-buffer)))
- (run-python cmd)
- (sleep-for 0 10)))
+ (run-python cmd)))
((and (eq 'python-mode org-babel-python-mode)
(fboundp 'py-shell)) ; python-mode.el
(require 'python-mode)
@@ -217,6 +216,8 @@ (defun org-babel-python-initiate-session-by-key (&optional session)
(py-shell nil nil t org-babel-python-command py-buffer nil nil t nil)))
(t
(error "No function available for running an inferior Python")))
+ ;; Wait until Python initializes.
+ (org-babel-comint-wait-for-output py-buffer)
(setq org-babel-python-buffers
(cons (cons session py-buffer)
(assq-delete-all session org-babel-python-buffers)))
--
2.35.1
That works for me. I'm using a series of python blocks to create org tables to be inserted in specific places in the document. So each block is named for that reason.
Do we need to worry about the note about not appropriate for large blocks of code or does that not apply in this case with the way you implemented it.
(org-babel-comint-wait-for-output BUFFER)
Wait until output arrives from BUFFER.
Note: this is only safe when waiting for the result of a single
statement (not large blocks of code).
Mark
[Message part 2 (text/html, inline)]
This bug report was last modified 2 years and 292 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.