ob-python: Check for end of output in org-babel-python-send-string

This is an attempt to mitigate occasional leaky prompts in CI. My
current hypothesis is that this could happen if the comint-output ends
between `org-babel-python-eoe-indicator' and the new prompt. Then the
new prompt could be injected into the output of the next unit test. To
avoid this, check we are at an ending prompt before exiting
`org-babel-python-send-string'.

https://list.orgmode.org/873506j7ky.fsf@localhost/

* lisp/ob-python.el (org-babel-python-send-string): Add check for
`python-shell-comint-end-of-output-p' to stop while loop accepting
process output.
This commit is contained in:
Jack Kamm 2023-10-15 16:15:09 -07:00
parent 061988c024
commit 1eb5987589
1 changed files with 4 additions and 3 deletions

View File

@ -399,9 +399,10 @@ finally:
(org-babel-python-without-earmuffs session))) (org-babel-python-without-earmuffs session)))
(python-shell-send-string body)) (python-shell-send-string body))
;; same as `python-shell-comint-end-of-output-p' in emacs-25.1+ ;; same as `python-shell-comint-end-of-output-p' in emacs-25.1+
(while (not (string-match (while (not (and (python-shell-comint-end-of-output-p string-buffer)
(string-match
org-babel-python-eoe-indicator org-babel-python-eoe-indicator
string-buffer)) string-buffer)))
(accept-process-output (get-buffer-process (current-buffer)))) (accept-process-output (get-buffer-process (current-buffer))))
(org-babel-chomp (substring string-buffer 0 (match-beginning 0)))))) (org-babel-chomp (substring string-buffer 0 (match-beginning 0))))))