0

NOTE: After restarting the python session and deleting all of the cache files about five separate times, everything started working as expected and I can't replicate the problem. I would still be interested in any explanations of the original issue, though.

My Problem

I am working with a .org file with org-babel code blocks executing code in a single python session. After executing the first few blocks, once I get to a particular block, all subsequent attempts to execute code blocks with <C-c><C-c> result in the output of a file from my /tmp/ directory being inserted into the buffer. I am looking for any guidance on how to debug this issue. Can I reasonably assume this behavior is coming from babel and not from something in my python code? Are there more details that would help in solving this problem?

The particular block where this problem begins to occur is:

#+BEGIN_SRC python :session tv :results value
with open(impath / "imagenet_classes.txt") as f:
    labels = [line.strip() for line in f.readlines()]
#+END_SRC

This returns a cached file with the results of an earlier block:

#+BEGIN_SRC python :session tv :results value
out = resnet(batch_t)
out
#+END_SRC

out is a pytorch Tensor with 1000 values. After running the block noted above, all subsequent block return the contents of a cached file in /tmp/ with the pytorch Tensor out. This is true even of something very simple that does not reference any existing variables, such as:

#+BEGIN_SRC python :session tv :results value
1+1
#+END_SRC

#+RESULTS:
:results:
tensor([[ 8.0883e+00,  7.6359e+00,  7.5604e+00,  7.4837e+00,  7.2821e+00,
          7.0158e+00,  6.9879e+00,  5.7778e+00,  5.6043e+00,  5.5918e+00,
          5.5413e+00,  5.5319e+00,  5.4627e+00,  5.3930e+00,  5.2824e+00,
          5.1776e+00,  5.1715e+00,  5.0799e+00,  5.0772e+00,  5.0520e+00,
          5.0075e+00,  4.9391e+00,  4.9213e+00,  4.8950e+00,  4.8217e+00,
...(etc)

After executing this or any other block, the python session shows the following:

>>> open('/tmp/python-DDq6Hi', 'w').write(str(_))
>>> 

'org_babel_python_eoe'
14832
>>> >>> >>> 'org_babel_python_eoe'
>>> 

Where '/tmp/python-DDq6Hi' is the aforementioned tmp file with the Tensor printout.

Configuration

My default header args are as follows:

  (setq org-babel-default-header-args '((:eval . "never-export")
                                        (:exports . "both")
                                        (:cache . "no")
                                        (:results . "replace drawer")))

I added :cache . "no" after the emergence of this problem, but it didn't have any effect. I also tried deleting all of the cache files and restarting the python session, but ran into the same problem at the same place. I've also tried several variations of the :results header (outputs values, leaving it blank, etc.).

Org version: Org mode version 9.3.7 (9.3.7-24-g7b657c-elpaplus @ /home/djliden91/.emacs.d/elpa/org-plus-contrib-20200831/)

emacs version: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3) of 2020-08-28

python version: '3.8.5 (default, Jul 27 2020, 08:42:51) \n[GCC 10.1.0]'

6
  • 1
    There is no such thing as :results values - you probably mean :results value . That is the default so it's not going to make any difference in this case, but you should take care to specify exactly what you want: org-babel is not exactly a forgiving environment. – NickD Sep 4 '20 at 16:32
  • Thank you for the note! Updated my question with that fix. – dlid Sep 4 '20 at 16:35
  • 1
    Guessing that out.argmax() returns 14832. it looks as if org-babel is having trouble extracting that value from the session. Sessions in general seem to be buggier than the rest of the code, but without them you cannot split the code into multiple code blocks (well, you can, but you have to be much more careful, since there is no shared context between the blocks). One possible check is to stuff everything in a single code block and evaluate that (without a session) and seeing if you get the right thing. – NickD Sep 4 '20 at 16:59
  • After restarting the session and clearing the cached files for the fifth-or-so time, everything worked and the unwanted cached output stopped printing. I do not know why. The one more-or-less significant change I made was changing some of the headers from :results none to :results silent. Though changing them back did not cause the problem to return. Thank you for your help -- not sure what happened! – dlid Sep 4 '20 at 17:13
  • 1
    The trouble with thing working without clear reason is that they can break again without clear reason :-) – NickD Sep 4 '20 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.