emacs-jupyter / jupyter

An interface to communicate with Jupyter kernels.
GNU General Public License v3.0
947 stars 93 forks source link

ZMQ error when connecting to Jupyter server #419

Open midsbie opened 2 years ago

midsbie commented 2 years ago

I cannot seem to connect to my Jupyter server as, whenever I run M-x jupyter-connect-server-repl, an error in the ZMQ subprocess occurs.

Errors I'm getting:

error in process filter: zmq--subprocess-filter: Error in ZMQ subprocess: invalid-function, (" Error: Wrong type argument: listp, #<subr jupyter-server-ioloop--recv-messages>")
error in process filter: Error in ZMQ subprocess: invalid-function, (" Error: Wrong type argument: listp, #<subr jupyter-server-ioloop--recv-messages>")

cl--assertion-failed: Assertion failed: (process-live-p process)finalizer failed: (cl-no-primary-method jupyter-kill-kernel #s(jupyter-server-kernel-manager (#<finalizer used>) jupyter--kernel-managers #s(jupyter-server-kernel (#<finalizer used>) ("python3" nil :argv ["/opt/conda/bin/python" "-m" "ipykernel_launcher" "-f" "{connection_file}"] :env nil :display_name "Python 3 (ipykernel)" :language "python" :interrupt_mode "signal" :metadata (:debugger t)) eieio--unbound #s(jupyter-server "http://zeus:8888" "ws://zeus:8888" (("Authorization" . "token 9af3921e3d3ccc58ac3568a952b48f461e02c0ddde119c45")) (#s(hash-table size 1 test eql weakness value rehash-size 1.5 rehash-threshold 0.8125 data (t #s(jupyter-server-kernel-comm nil #2)))) #s(jupyter-server-ioloop (#<finalizer>) #<process zmq> nil ((disconnect-channels (kernel-id) ((let ((ws (jupyter-server-ioloop--kernel-ws kernel-id))) (jupyter-server-ioloop--recv-messages) (when ws (jupyter-server-ioloop--disconnect ws)) (list 'disconnect-channels kernel-id)))) (connect-channels (kernel-id) ((let ((ws (jupyter-server-ioloop--kernel-ws kernel-id))) (unless ws (url-cookie-parse-file) (jupyter-server-ioloop--connect kernel-id))) (jupyter-server-ioloop--recv-messages) (list 'connect-channels kernel-id))) (send (kernel-id channel msg-type msg msg-id) ((let ((ws (jupyter-server-ioloop--kernel-ws kernel-id))) (unless ws (error "Kernel with ID (%s) not connected" kernel-id)) (websocket-send-text ws (jupyter-encode-raw-message (plist-get (websocket-client-data ws) :session) msg-type :channel (substring (symbol-name channel) 1) :msg-id msg-id :content msg)) (jupyter-server-ioloop--recv-messages) (list 'sent kernel-id channel msg-id))))) ((jupyter-api-with-subprocess-setup (require 'jupyter-server-ioloop) (push 'jupyter-server-ioloop--recv-messages jupyter-ioloop-pre-hook) (setq jupyter-server-timeout (/ jupyter-ioloop-timeout 4) jupyter-ioloop-timeout (* 3 (/ jupyter-ioloop-timeout 4))) (setq jupyter-server-rest-client (jupyter-rest-client :url "http://zeus:8888" :ws-url "ws://zeus:8888" :auth '(("Authorization" . "token 9af3921e3d3ccc58ac3568a952b48f461e02c0ddde119c45")))))) nil "http://zeus:8888" "ws://zeus:8888" (("Authorization" . "token 9af3921e3d3ccc58ac3568a952b48f461e02c0ddde119c45"))) (:default "python3" :kernelspecs (("python3" nil :argv ["/opt/conda/bin/python" "-m" "ipykernel_launcher" "-f" "{connection_file}"] :env nil :display_name "Python 3 (ipykernel)" :language "python" :interrupt_mode "signal" :metadata (:debugger t))))) "37741d3b-15b7-492e-9b84-9a9220016424") #s(jupyter-server-kernel-comm nil #s(jupyter-server-kernel (#<finalizer used>) ("python3" nil :argv ["/opt/conda/bin/python" "-m" "ipykernel_launcher" "-f" "{connection_file}"] :env nil :display_name "Python 3 (ipykernel)" :language "python" :interrupt_mode "signal" :metadata (:debugger t)) eieio--unbound #s(jupyter-server "http://zeus:8888" "ws://zeus:8888" (("Authorization" . "token 9af3921e3d3ccc58ac3568a952b48f461e02c0ddde119c45")) (#s(hash-table size 1 test eql weakness value rehash-size 1.5 rehash-threshold 0.8125 data (t #2))) #s(jupyter-server-ioloop (#<finalizer>) #<process zmq> nil ((disconnect-channels (kernel-id) ((let ((ws (jupyter-server-ioloop--kernel-ws kernel-id))) (jupyter-server-ioloop--recv-messages) (when ws (jupyter-server-ioloop--disconnect ws)) (list 'disconnect-channels kernel-id)))) (connect-channels (kernel-id) ((let ((ws (jupyter-server-ioloop--kernel-ws kernel-id))) (unless ws (url-cookie-parse-file) (jupyter-server-ioloop--connect kernel-id))) (jupyter-server-ioloop--recv-messages) (list 'connect-channels kernel-id))) (send (kernel-id channel msg-type msg msg-id) ((let ((ws (jupyter-server-ioloop--kernel-ws kernel-id))) (unless ws (error "Kernel with ID (%s) not connected" kernel-id)) (websocket-send-text ws (jupyter-encode-raw-message (plist-get (websocket-client-data ws) :session) msg-type :channel (substring (symbol-name channel) 1) :msg-id msg-id :content msg)) (jupyter-server-ioloop--recv-messages) (list 'sent kernel-id channel msg-id))))) ((jupyter-api-with-subprocess-setup (require 'jupyter-server-ioloop) (push 'jupyter-server-ioloop--recv-messages jupyter-ioloop-pre-hook) (setq jupyter-server-timeout (/ jupyter-ioloop-timeout 4) jupyter-ioloop-timeout (* 3 (/ jupyter-ioloop-timeout 4))) (setq jupyter-server-rest-client (jupyter-rest-client :url "http://zeus:8888" :ws-url "ws://zeus:8888" :auth '(("Authorization" . "token 9af3921e3d3ccc58ac3568a952b48f461e02c0ddde119c45")))))) nil "http://zeus:8888" "ws://zeus:8888" (("Authorization" . "token 9af3921e3d3ccc58ac3568a952b48f461e02c0ddde119c45"))) (:default "python3" :kernelspecs (("python3" nil :argv ["/opt/conda/bin/python" "-m" "ipykernel_launcher" "-f" "{connection_file}"] :env nil :display_name "Python 3 (ipykernel)" :language "python" :interrupt_mode "signal" :metadata (:debugger t))))) "37741d3b-15b7-492e-9b84-9a9220016424"))))

Relevant logs from Jupyter server (in Docker):

[I 2022-11-20 14:23:35.243 ServerApp] Serving notebooks from local directory: /home/jupyter
[I 2022-11-20 14:23:35.243 ServerApp] Jupyter Server 1.23.0 is running at:
[I 2022-11-20 14:23:35.243 ServerApp] http://ed4f873a7828:8888/lab?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[I 2022-11-20 14:23:35.243 ServerApp]  or http://127.0.0.1:8888/lab?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[I 2022-11-20 14:23:35.243 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Running Jupyter Server v1.23.0 and JupyterLab 3.5.0.

midsbie commented 2 years ago

When I toggle-debug-on-error, I get the following error dump:

Debugger entered--Lisp error: (zmq-subprocess-error invalid-function (" Error: Wrong type argument: listp, #<subr jupyter..."))
  signal(zmq-subprocess-error (invalid-function (" Error: Wrong type argument: listp, #<subr jupyter...")))
  zmq--subprocess-filter(#<process zmq> "(error invalid-function (\" Error: Wrong type argum...")
  accept-process-output(nil 0.25)
  jupyter-ioloop-wait-until(#<jupyter-server-ioloop jupyter-server-ioloop-155a3b5b7dd8> start identity)
  #f(compiled-function (arg1 arg2 &rest rest) #<bytecode 0x6f7c4c8acc9618e>)(#<jupyter-server-ioloop jupyter-server-ioloop-155a3b5b7dd8> #f(compiled-function (event) #<bytecode -0x7d4fdf1bd2230d>))
  apply(#f(compiled-function (arg1 arg2 &rest rest) #<bytecode 0x6f7c4c8acc9618e>) #<jupyter-server-ioloop jupyter-server-ioloop-155a3b5b7dd8> #f(compiled-function (event) #<bytecode -0x7d4fdf1bd2230d>))
  jupyter-ioloop-start(#<jupyter-server-ioloop jupyter-server-ioloop-155a3b5b7dd8> #f(compiled-function (event) #<bytecode -0x7d4fdf1bd2230d>))
  #f(compiled-function (comm) #<bytecode 0x1f49ae75dbeabcbd>)(#<jupyter-server jupyter-server-155a3b6daa3c>)
  apply(#f(compiled-function (comm) #<bytecode 0x1f49ae75dbeabcbd>) #<jupyter-server jupyter-server-155a3b6daa3c>)
  #f(compiled-function (&rest cnm-args) #<bytecode -0x84dc6af3e363f20>)()
  #f(compiled-function (cl--cnm comm) #<bytecode -0x16f3942056b565b9>)(#f(compiled-function (&rest cnm-args) #<bytecode -0x84dc6af3e363f20>) #<jupyter-server jupyter-server-155a3b6daa3c>)
  apply(#f(compiled-function (cl--cnm comm) #<bytecode -0x16f3942056b565b9>) #f(compiled-function (&rest cnm-args) #<bytecode -0x84dc6af3e363f20>) #<jupyter-server jupyter-server-155a3b6daa3c>)
  #f(compiled-function (&rest args) #<bytecode -0x14a4486b9fcac5fa>)(#<jupyter-server jupyter-server-155a3b6daa3c>)
  apply(#f(compiled-function (&rest args) #<bytecode -0x14a4486b9fcac5fa>) #<jupyter-server jupyter-server-155a3b6daa3c> nil)
  jupyter-comm-start(#<jupyter-server jupyter-server-155a3b6daa3c>)
  #f(compiled-function (comm &rest ignore) "Register COMM to receive server events.\nIf SERVER receives events that have the same kernel ID as the\nkernel associated with COMM, then COMM's `jupyter-event-handler'\nwill receive those events." #<bytecode 0x117bb0b34a635b89>)(#<jupyter-server-kernel-comm jupyter-server-kernel-comm-155a3bdc5618>)
  apply(#f(compiled-function (comm &rest ignore) "Register COMM to receive server events.\nIf SERVER receives events that have the same kernel ID as the\nkernel associated with COMM, then COMM's `jupyter-event-handler'\nwill receive those events." #<bytecode 0x117bb0b34a635b89>) #<jupyter-server-kernel-comm jupyter-server-kernel-comm-155a3bdc5618> nil)
  jupyter-comm-start(#<jupyter-server-kernel-comm jupyter-server-kernel-comm-155a3bdc5618>)
  #f(compiled-function (manager) "Start a websocket connection to MANAGER's kernel.\nMANAGER's COMM slot will be set to the `jupyter-comm-layer'\nreceiving events on the websocket when this method returns." #<bytecode -0x41d78d64cd27427>)(#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4>)
  apply(#f(compiled-function (manager) "Start a websocket connection to MANAGER's kernel.\nMANAGER's COMM slot will be set to the `jupyter-comm-layer'\nreceiving events on the websocket when this method returns." #<bytecode -0x41d78d64cd27427>) #<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> nil)
  jupyter-comm-start(#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4>)
  #f(compiled-function (manager class &rest slots) #<bytecode 0x1d100d0bab02d5fa>)(#f(compiled-function (&rest cnm-args) #<bytecode 0xa86dc1fdfd2487b>) #<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client)
  apply(#f(compiled-function (manager class &rest slots) #<bytecode 0x1d100d0bab02d5fa>) #f(compiled-function (&rest cnm-args) #<bytecode 0xa86dc1fdfd2487b>) (#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client))
  #f(compiled-function (&rest args) #<bytecode 0x1e9f9963f2f82234>)(#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client)
  apply(#f(compiled-function (&rest args) #<bytecode 0x1e9f9963f2f82234>) (#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client))
  #f(compiled-function (&rest args) #<bytecode -0x158969df9a4c6a2a>)(#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client)
  apply(#f(compiled-function (&rest args) #<bytecode -0x158969df9a4c6a2a>) #<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client)
  jupyter-make-client(#<jupyter-server-kernel-manager jupyter-server-kernel-manager-155a3baa55c4> jupyter-repl-client)
  jupyter-connect-server-repl(#<jupyter-server jupyter-server-155a3b6daa3c> "b4975a59-01dd-4e73-b87f-fa0d99d9b31a" nil t nil t)
  funcall-interactively(jupyter-connect-server-repl #<jupyter-server jupyter-server-155a3b6daa3c> "b4975a59-01dd-4e73-b87f-fa0d99d9b31a" nil t nil t)
  command-execute(jupyter-connect-server-repl record)
  execute-extended-command(nil "jupyter-connect-server-repl" nil)
  funcall-interactively(execute-extended-command nil "jupyter-connect-server-repl" nil)
  command-execute(execute-extended-command)
moritzschaefer commented 1 year ago

Same for me since I updated recently. Any updates @miguel-guedes Did you already try downgrading packages to see which version combination works?

Here are my versions: IPython : 8.4.0 ipykernel : 6.15.2 ipywidgets : 7.6.5 jupyter_client : 7.3.5 jupyter_core : 4.11.1 jupyter_server : 1.18.1 jupyterlab : 3.4.4

Jupyter server is much older than yours, so I suspect that the emacs-jupyter (or the emacs-zmq package) leads to this problem..

nakkaya commented 1 year ago

@miguel-guedes @moritzschaefer See issue #297 for a possible fix.

moritzschaefer commented 1 year ago

I already had "jupyter" and "zmq" on that list but I'll test whether the regex wildcards help

nakkaya commented 1 year ago

@moritzschaefer wildcards should fix it, without them it does not work.