|
From: | Andreas Röhler |
Subject: | Re: [O] python sessions |
Date: | Wed, 20 Mar 2013 07:44:43 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 |
Am 20.03.2013 04:07, schrieb Nick Dokos:
John Hendy <address@hidden> wrote:On Tue, Mar 19, 2013 at 4:40 PM, Gary Oberbrunner <address@hidden> wrote:I must be failing to understand something. I'm running Emacs 24.3 on Windows, with latest trunk org-mode. I can't get python functions to persist across blocks in session mode. Here's my foo.org: =============== * My Document #+BEGIN_SRC python :exports results :results output :session def foo(x): return x+1 print "hi" #+END_SRC #+RESULTS: : hi #+BEGIN_SRC python :exports results :results output :session print foo(100) print "bye" #+END_SRC ======================== In session mode, shouldn't foo be defined in the second python block? When I export this, I get "NameError: name 'foo' is not defined" I may be doing something wrong, because if I name my python session, I never see a buffer of that name, and I expected to. Any help? -- GaryYou should probably post your babel configuration from .emacs. This works for me (mostly). I'm using python 3.3 and so the print function has changed to requiring parentheses. I can switch to a buffer called *Python*, however, and =print("hi")= works fine. If I change to =print(foo(100))=, I get 101 in the #+RESULTS block.I don't - I get the same error as Gary. And looking at the code of org-babel-python-initiate-session-by-key, I don't understand how it's supposed to work: python-buffer is nil to begin with; the cond takes the first branch and starts a python session. When we come to (setq org-babel-python-buffers (cons (cons session python-buffer) (assq-delete-all session org-babel-python-buffers))) python-buffer is still nil, so we are cooked. Maybe python-buffer was set as a side-effect of run-python in earlier versions of emacs? If so, it does not seem to be the case now. Nick Org-mode version 8.0-pre (release_8.0-pre-144-g855dcf.dirty @ /home/nick/elisp/org-mode/lisp/) GNU Emacs 24.3.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4) of 2012-12-29 on alphaville
AFAIU :session is broken, because Python shell as opened by run-python or py-shell isn't used by ob-babel. Seems ob-babel sends it's code w/ an own shell command, thus opening a new python shell internally every time. Did :session ever work? Then I might be wrong with this comment. Andreas
[Prev in Thread] | Current Thread | [Next in Thread] |