0

I've started a jupyter kernel form emacs-jupyter. I'd like to get the process id for the python process associated with the buffer so that I can attach a debugger to it. How can I do this in elisp?

1
0

Something like this:

(process-id (get-buffer-process (current-buffer)))

should do it. You can replace the call to current-buffer by some other means of identifying the buffer of interest, and you should probably check that the result of get-buffer-process is not nil.

5
  • Thanks for the response. This was my first try, but get-buffer-process returns nil. I don't understand because there is clearly a python process associated with the buffer (jupyter kernel). May 18 at 18:15
  • If get-buffer-process returns nil, then there is no process associated with the buffer (if you kill the buffer with C-x k, it asks for confirmation if there is a process associated with the buffer - that's what happens e.g. when you start a shell with M-x shell and then try to kill the *shell* buffer - does it do that if you try to kill the jupyter-kernel buffer?) You might have to delve a bit deeper into what emacs-jupyter does to figure out what process is associated with what buffer.
    – NickD
    May 18 at 18:32
  • It suggests Jupyter REPL (*jupyter-repl[python 3.9.4]*<2>) still connected. Kill it? (y or n) when I kill the buffer. So I would think there is a process associated with the buffer. I did browse the emacs-jupyter code a bit, but unfortunately I am not an elisp expert. May 18 at 18:55
  • 1
    Since the error mentions jupyter-repl and get-buffer-process returns nil, I checked and indeed, the error originates from that source file: github.com/nnicandro/emacs-jupyter/blob/master/… You're correct, there must be a process that Emacs is communicating with. Looking through the same file shows that the REPL start process uses jupyter-kernel-process-manager, of which there is also a source file. That's where you can find the Emacs process handle. Hopefully that helps. May 19 at 13:16
  • 1
    This line looks promising: github.com/nnicandro/emacs-jupyter/blob/… I'd throw a message statement in there or jump in a debugger to see what the kernel object looks like. (Of course, you could track down its definition and see if there's a slot (i.e. attribute) for what you want). There is also something called jupyter--debug referenced in the code; that might have the info you need or give a hint at how to get it. May 19 at 13:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.