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.