GNU bug report logs - #50514
28.0.50; org inline call to python src block req C-g to break

Previous Next

Package: org-mode;

Reported by: "Barton, Mark" <Mark.Barton <at> disney.com>

Date: Fri, 10 Sep 2021 23:13:01 UTC

Severity: normal

Full log


Message #84 received at 50514 <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> gmail.com>
To: "Barton, Mark" <Mark.Barton <at> disney.com>
Cc: "50514 <at> debbugs.gnu.org" <50514 <at> debbugs.gnu.org>,
 Mark Barton <mbarton98 <at> gmail.com>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 Augusto Stoffel <arstoffel <at> gmail.com>
Subject: Re: bug#50514: 28.0.50; org inline call to python src block req C-g
 to break
Date: Sun, 28 Aug 2022 09:30:22 +0800
[Message part 1 (text/plain, inline)]
"Barton, Mark" <Mark.Barton <at> disney.com> writes:

> I tried something that was suggested last September 14th by Augusto Stoffel. I had not tried it because changing the sleep from 10 to 90 was my workaround.
> One thing that might work is to block until the shell is ready with something like
>
>     (run-python)
>     (with-current-buffer *the-shell-buffer*
>       (while (not python-shell--first-prompt-received)
>         (accept-process-output (get-buffer-process (current-buffer)))))

Thanks, but it is not a good solution. Org cannot rely on internal
variables inside python.el (python-shell--first-prompt-received is an
internal variable). Internal variables are a subject of change without
notice.

May you instead try the attached alternative patch?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92

[v2-0001-ob-python-Fix-Emacs-bug-50514-when-Python-loads-s.patch (text/x-patch, inline)]
From 06373a64387330d5bbdcbb3417cea7c2638713df Mon Sep 17 00:00:00 2001
Message-Id: <06373a64387330d5bbdcbb3417cea7c2638713df.1661650102.git.yantar92 <at> gmail.com>
From: Ihor Radchenko <yantar92 <at> gmail.com>
Date: Sat, 27 Aug 2022 22:06:11 +0800
Subject: [PATCH v2] 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'.
---
 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


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.