From: "Barton, Mark" <Mark.Barton@disney.com>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: "50514@debbugs.gnu.org" <50514@debbugs.gnu.org>,
Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#50514: 28.0.50; org inline call to python src block req C-g to break
Date: Tue, 14 Sep 2021 17:54:22 +0000 [thread overview]
Message-ID: <32AF1DCB-F81A-4FB7-8EB2-31B483E5E468@disney.com> (raw)
In-Reply-To: <87r1dry7x0.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4532 bytes --]
On Sep 13, 2021, at 11:42 PM, Augusto Stoffel <arstoffel@gmail.com<mailto:arstoffel@gmail.com>> wrote:
Hi Mark,
After removing the patch to ob-python.el and applying the attached patch
to python.el, could you please test that your notebooks work again?
This will probably not change the independent initialization problem
that you describe (but it might, who knows). If you want to help me
understanding that part, you can do
M-x trace-function RET python-shell-send-string-no-output
M-x trace-function RET python-shell-output-filter-buffer
M-x trace-function RET python-shell-completion-native-get-completions
and send the result printed to 'trace-buffer'. Thanks!
<0001-Python-shell-rearrange-printing-of-newline-before-ou.patch>
That patch fixes the multiline result error for me with the unpatched ob-python.el. I noticed yesterday the command in the tmp file was prefixed with \n and now with the patch it is not and org babel processes it fine as an inline function call to add the result within the text of the document.
I was not able to find python-shell-output-filter-buffer to trace so I substituted python-shell-output-filter. Here is the trace-output for my initial C-c C-c on the call inline function. As you suspected the initialization problem is still there for me, but perhaps this will shed some light on that. Below this is the trace for the second and successful call to the inline function.
#+begin_example Trace from initial execution that requires C-g to break
======================================================================
1 -> (python-shell-send-string-no-output "def __PYTHON_EL_eval(source, filename):
import ast, sys
if sys.version_info[0] == 2:
from __builtin__ import compile, eval, globals
else:
from builtins import compile, eval, globals
try:
p, e = ast.parse(source, filename), None
except SyntaxError:
t, v, tb = sys.exc_info()
sys.excepthook(t, v, tb.tb_next)
return
if p.body and isinstance(p.body[-1], ast.Expr):
e = p.body.pop()
try:
g = globals()
exec(compile(p, filename, 'exec'), g, g)
if e:
return eval(compile(ast.Expression(e.value), filename, 'eval'), g, g)
except Exception:
t, v, tb = sys.exc_info()
sys.excepthook(t, v, tb.tb_next)")
| 2 -> (python-shell-output-filter "Traceback (most recent call last):
File \"<stdin>\", line 1, in <module>
NameError: name '__PYTHON_EL_eval' is not defined
")
| 2 <- python-shell-output-filter: ""
| 2 -> (python-shell-output-filter ">>> ")
| 2 <- python-shell-output-filter: ""
1 <- python-shell-send-string-no-output: "Traceback (most recent call last):
File \"<stdin>\", line 1, in <module>
NameError: name '__PYTHON_EL_eval' is not defined"
======================================================================
1 -> (python-shell-send-string-no-output "def __PYTHON_EL_eval_file(filename, tempname, delete):
import codecs, os, re
pattern = r'^[ ]*#.*?coding[:=][ ]*([-_.a-zA-Z0-9]+)'
with codecs.open(tempname or filename, encoding='latin-1') as file:
match = re.match(pattern, file.readline())
match = match or re.match(pattern, file.readline())
encoding = match.group(1) if match else 'utf-8'
with codecs.open(tempname or filename, encoding=encoding) as file:
source = file.read().encode(encoding)
if delete and tempname:
os.remove(tempname)
return __PYTHON_EL_eval(source, filename)")
| 2 -> (python-shell-output-filter ">>> ")
| 2 <- python-shell-output-filter: ""
1 <- python-shell-send-string-no-output: ""
#+end_example
There was nothing showing up in the trace, until I added the python-shell-send-string to the list of trace functions.
#+begin_example Existing Python session and now works without the ob-python.el patch that modified chomp value
======================================================================
1 -> (python-shell-send-string "try:
with open('/var/folders/kf/zdpzgs9d30b3jj4bdkdjf1vw0000gn/T/babel-eaPALH/python-ca4zF3') as __org_babel_python_tmpfile:
exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))
except:
raise
finally:
print('org_babel_python_eoe')")
1 <- python-shell-send-string: nil
#+end_example
FYI the contents of that tmp file is:
#+begin_example Tmp file contents
print("testing23", end=“")
#+end_example
[-- Attachment #2: Type: text/html, Size: 10613 bytes --]
next prev parent reply other threads:[~2021-09-14 17:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-10 23:06 bug#50514: 28.0.50; org inline call to python src block req C-g to break Barton, Mark
2021-09-11 13:04 ` Lars Ingebrigtsen
2021-09-11 13:26 ` Augusto Stoffel
2021-09-12 6:22 ` Barton, Mark
2021-09-12 6:51 ` Augusto Stoffel
2021-09-12 8:27 ` Barton, Mark
2021-09-12 9:15 ` Augusto Stoffel
2021-09-12 17:00 ` Barton, Mark
2021-09-12 20:04 ` Barton, Mark
2021-09-14 6:42 ` Augusto Stoffel
2021-09-14 17:54 ` Barton, Mark [this message]
2021-09-14 18:29 ` Augusto Stoffel
2021-09-14 19:25 ` Barton, Mark
2021-09-14 19:31 ` Augusto Stoffel
2021-09-14 22:20 ` Barton, Mark
2021-09-15 6:28 ` Augusto Stoffel
2021-09-14 19:36 ` Augusto Stoffel
2021-09-15 8:02 ` Lars Ingebrigtsen
2022-08-25 15:12 ` Lars Ingebrigtsen
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.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32AF1DCB-F81A-4FB7-8EB2-31B483E5E468@disney.com \
--to=mark.barton@disney.com \
--cc=50514@debbugs.gnu.org \
--cc=arstoffel@gmail.com \
--cc=larsi@gnus.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.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).