emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Barton, Mark" <Mark.Barton@disney.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: "50514@debbugs.gnu.org" <50514@debbugs.gnu.org>,
	Lars Ingebrigtsen <larsi@gnus.org>,
	Augusto Stoffel <arstoffel@gmail.com>
Subject: bug#50514: 28.0.50; org inline call to python src block req C-g to break
Date: Sun, 28 Aug 2022 01:56:13 +0000	[thread overview]
Message-ID: <0324EA8C-CB50-473E-A106-68DA2437C90E@disney.com> (raw)
In-Reply-To: <87czclduj5.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1958 bytes --]



On Aug 27, 2022, at 6:30 PM, Ihor Radchenko <yantar92@gmail.com<mailto:yantar92@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

[-- Attachment #2: Type: text/html, Size: 31975 bytes --]

  reply	other threads:[~2022-08-28  1:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <24B9F777-2B69-45FD-ADBB-11E7A18F7A9A@disney.com>
     [not found] ` <87wnnnjlav.fsf@gmail.com>
     [not found]   ` <AEC70ED1-96FB-4FC9-9971-EA0C5421BC8A@disney.com>
     [not found]     ` <871r5u1e3m.fsf@gmail.com>
     [not found]       ` <61CB9513-0EEC-4F46-90D6-1D208BBADFA1@disney.com>
     [not found]         ` <87pmteb1ef.fsf@gmail.com>
     [not found]           ` <21C76818-63E5-4DC9-A60D-2BEF33813A18@disney.com>
     [not found]             ` <73383502-159B-4BD9-8836-6C8A534A7063@disney.com>
     [not found]               ` <87r1dry7x0.fsf@gmail.com>
     [not found]                 ` <32AF1DCB-F81A-4FB7-8EB2-31B483E5E468@disney.com>
     [not found]                   ` <87sfy7qadr.fsf@gmail.com>
     [not found]                     ` <073CC0D1-9900-4613-87E8-D69EA1C11623@disney.com>
     [not found]                       ` <87k0jjq79k.fsf@gmail.com>
     [not found]                         ` <87k0jiuuzc.fsf@gnus.org>
     [not found]                           ` <87mtbsgxwh.fsf@gnus.org>
2022-08-26 13:30                             ` bug#50514: 28.0.50; org inline call to python src block req C-g to break Ihor Radchenko
2022-08-27 13:16                               ` Lars Ingebrigtsen
2022-08-27 14:11                                 ` Ihor Radchenko
2022-08-27 18:56                                   ` Barton, Mark
2022-08-27 21:31                                     ` Mark Barton
2022-08-28  0:38                                       ` Barton, Mark
2022-08-28  1:30                                         ` Ihor Radchenko
2022-08-28  1:56                                           ` Barton, Mark [this message]
2022-08-28  2:55                                             ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0324EA8C-CB50-473E-A106-68DA2437C90E@disney.com \
    --to=mark.barton@disney.com \
    --cc=50514@debbugs.gnu.org \
    --cc=arstoffel@gmail.com \
    --cc=larsi@gnus.org \
    --cc=yantar92@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).