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 Answer
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.
- Thanks for the response. This was my first try, but
get-buffer-processreturns nil. I don't understand because there is clearly a python process associated with the buffer (jupyter kernel).James Pritts– James Pritts2021-05-18 18:15:55 +00:00Commented May 18, 2021 at 18:15 - If
get-buffer-processreturnsnil, then there is no process associated with the buffer (if you kill the buffer withC-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 withM-x shelland 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 whatemacs-jupyterdoes to figure out what process is associated with what buffer.NickD– NickD2021-05-18 18:32:56 +00:00Commented May 18, 2021 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.James Pritts– James Pritts2021-05-18 18:55:36 +00:00Commented May 18, 2021 at 18:55 - 1Since the error mentions
jupyter-replandget-buffer-processreturnsnil, 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 usesjupyter-kernel-process-manager, of which there is also a source file. That's where you can find the Emacs process handle. Hopefully that helps.Lorem Ipsum– Lorem Ipsum2021-05-19 13:16:11 +00:00Commented May 19, 2021 at 13:16 - 1This line looks promising: github.com/nnicandro/emacs-jupyter/blob/… I'd throw a
messagestatement 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 calledjupyter--debugreferenced in the code; that might have the info you need or give a hint at how to get it.Lorem Ipsum– Lorem Ipsum2021-05-19 13:23:53 +00:00Commented May 19, 2021 at 13:23