From: Liu Hui <liuhui1610@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ob-python: Fix async evaluation
Date: Tue, 11 Jul 2023 11:40:39 +0800 [thread overview]
Message-ID: <CAOQTW-PteV0DrBBpE6zxLj+3AxLOTqHVQEvEp5TPtwWHwd6RaA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 700 bytes --]
Hi,
To reproduce the bug:
1. create test.org:
──────────────────✀──────────────────
#+begin_src python :session "*Python 3*" :async t
1
#+end_src
# Local Variables:
# python-shell-buffer-name: "Python 3"
# End:
──────────────────✀──────────────────
2. emacs -Q -L <path_to_latest_org> --eval "(require 'ob-python)"
3. Open test.org, then start a python shell with M-x run-python, which
should create a buffer named "*Python 3*"
4. Press C-c C-c on the src block. Then an error "No inferior Python
process running" is shown.
[-- Attachment #2: 0001-ob-python-Fix-async-evaluation.patch --]
[-- Type: text/x-patch, Size: 2880 bytes --]
From 75ca16a21fe409aeb37b9bf0d97895c00f38d466 Mon Sep 17 00:00:00 2001
From: Liu Hui <liuhui1610@gmail.com>
Date: Tue, 11 Jul 2023 10:49:07 +0800
Subject: [PATCH] ob-python: Fix async evaluation
* lisp/ob-python.el (org-babel-python-async-evaluate-session): Bind
`python-shell-buffer-name' inside the temp buffer.
---
lisp/ob-python.el | 47 +++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 0e0539d7a..c15d45b96 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -400,28 +400,31 @@ (defun org-babel-python-async-evaluate-session
session (current-buffer)
"ob_comint_async_python_\\(.+\\)_\\(.+\\)"
'org-babel-chomp 'org-babel-python-async-value-callback)
- (let ((python-shell-buffer-name (org-babel-python-without-earmuffs session)))
- (pcase result-type
- (`output
- (let ((uuid (org-id-uuid)))
- (with-temp-buffer
- (insert (format org-babel-python-async-indicator "start" uuid))
- (insert "\n")
- (insert body)
- (insert "\n")
- (insert (format org-babel-python-async-indicator "end" uuid))
- (python-shell-send-buffer))
- uuid))
- (`value
- (let ((tmp-results-file (org-babel-temp-file "python-"))
- (tmp-src-file (org-babel-temp-file "python-")))
- (with-temp-file tmp-src-file (insert body))
- (with-temp-buffer
- (insert (org-babel-python-format-session-value tmp-src-file tmp-results-file result-params))
- (insert "\n")
- (insert (format org-babel-python-async-indicator "file" tmp-results-file))
- (python-shell-send-buffer))
- tmp-results-file)))))
+ (pcase result-type
+ (`output
+ (let ((uuid (org-id-uuid)))
+ (with-temp-buffer
+ (insert (format org-babel-python-async-indicator "start" uuid))
+ (insert "\n")
+ (insert body)
+ (insert "\n")
+ (insert (format org-babel-python-async-indicator "end" uuid))
+ (let ((python-shell-buffer-name
+ (org-babel-python-without-earmuffs session)))
+ (python-shell-send-buffer)))
+ uuid))
+ (`value
+ (let ((tmp-results-file (org-babel-temp-file "python-"))
+ (tmp-src-file (org-babel-temp-file "python-")))
+ (with-temp-file tmp-src-file (insert body))
+ (with-temp-buffer
+ (insert (org-babel-python-format-session-value tmp-src-file tmp-results-file result-params))
+ (insert "\n")
+ (insert (format org-babel-python-async-indicator "file" tmp-results-file))
+ (let ((python-shell-buffer-name
+ (org-babel-python-without-earmuffs session)))
+ (python-shell-send-buffer)))
+ tmp-results-file))))
(provide 'ob-python)
--
2.25.1
next reply other threads:[~2023-07-11 3:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 3:40 Liu Hui [this message]
2023-07-11 9:14 ` [PATCH] ob-python: Fix async evaluation Ihor Radchenko
2023-07-12 4:51 ` Jack Kamm
2023-07-12 10:11 ` Liu Hui
2023-07-12 21:58 ` Jack Kamm
2023-07-13 9:59 ` Liu Hui
2023-07-14 0:29 ` Jack Kamm
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=CAOQTW-PteV0DrBBpE6zxLj+3AxLOTqHVQEvEp5TPtwWHwd6RaA@mail.gmail.com \
--to=liuhui1610@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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).