emacs-jupyter / jupyter

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

emacs 30, macos, zmq error #542

Open danielpopescu opened 1 week ago

danielpopescu commented 1 week ago

Hello,

Just started getting this error (org version 9.7.5, latest of everything, macos, native compilation):

error in process filter: progn: Error in ZMQ subprocess: wrong-type-argument, (listp #[(ctx) ((setq load-path (cons "/.emacs.d/elpa/jupyter-20240420.1918/" load-path)) (require 'jupyter-ioloop) (setq jupyter-ioloop-poller (zmq-poller)) (setq jupyter-ioloop-stdin (let ((sock (zmq-socket ctx zmq-PAIR))) (prog1 sock (zmq-connect sock (format "tcp://127.0.0.1:%s" 51351))))) (zmq-poller-add jupyter-ioloop-poller jupyter-ioloop-stdin zmq-POLLIN) (let (events) (condition-case nil (progn (setq jupyter-channel-ioloop-session (let ((conn-info nil) (id "ee0db486-5825-441f-b599-a03b84903670") (key "69613b3a-165b-4715-9789-747ded51ac6b")) (progn (record 'jupyter-session conn-info id key)))) (require 'jupyter-channel-ioloop) (require 'jupyter-zmq-channel-ioloop) (setq jupyter-ioloop-post-hook (cons 'jupyter-zmq-channel-ioloop--recv-messages jupyter-ioloop-post-hook)) (let ((--cl-var-- '(:shell :stdin :iopub :control)) (channel nil)) (while (consp --cl-var--) (setq channel (car --cl-var--)) (if (object-assoc channel :type jupyter-channel-ioloop-channels) (progn) (setq jupyter-channel-ioloop-channels (cons (jupyter-zmq-channel :session jupyter-channel-ioloop-session :type channel) jupyter-channel-ioloop-channels))) (setq --cl-var-- (cdr --cl-var--))) nil) (setq jupyter-ioloop-pre-hook (mapcar #'(lambda (f) (if (symbolp f) (progn (setq f (symbol-function f)))) (if (byte-code-function-p f) nil (byte-compile f))) (append jupyter-ioloop-pre-hook 'nil))) (zmq-prin1 '(start)) (let ((on-stdin (byte-compile #'(lambda nil (let ((cmd (read (zmq-recv jupyter-ioloop-stdin))) (res (if (consp cmd) (let ((x37 (car-safe cmd))) (cond ((eq x37 'send) (let ((x38 (cdr-safe cmd))) (if (consp x38) (let ((x39 (car-safe x38)) (x40 (funcall #'(lambda (x) (or (object-assoc x :type jupyter-channel-ioloop-channels) (error "Channel not alive (%s)" x))) x39)) (x41 (cdr-safe x38))) (if (consp x41) (let ((x42 (car-safe x41)) (x43 (cdr-safe x41))) (if (consp x43) (let ((x44 (car-safe x43)) (x45 (cdr-safe x43))) (if (consp x45) (let ((x46 (car-safe x45)) (x47 (cdr-safe x45))) (if (null x47) (let ((channel x40) (msg-type x42) (msg x44) (msg-id x46)) (list 'sent (eieio-oref channel 'type) (jupyter-send channel msg-type msg msg-id))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd))))) ((eq x37 'stop-channel) (let ((x48 (cdr-safe cmd))) (if (consp x48) (let ((x49 (car-safe x48)) (x50 (cdr-safe x48))) (if (null x50) (let ((type x49)) (let ((channel (object-assoc type :type jupyter-channel-ioloop-channels))) (if (and channel (jupyter-alive-p channel)) (progn (jupyter-stop channel))) (list 'stop-channel type))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd))))) ((eq x37 'start-channel) (let ((x51 (cdr-safe cmd))) (if (consp x51) (let ((x52 (car-safe x51)) (x53 (funcall #'(lambda (x) (or (object-assoc x :type jupyter-channel-ioloop-channels) (error "Channel not alive (%s)" x))) x52)) (x54 (cdr-safe x51))) (if (consp x54) (let ((x55 (car-safe x54)) (x56 (cdr-safe x54))) (if (null x56) (let ((channel x53) (endpoint x55)) (if (jupyter-alive-p channel) (progn (jupyter-stop channel))) (eieio-oset channel 'endpoint endpoint) (let ((identity (let ((cl-x jupyter-channel-ioloop-session)) (progn (or (let ((cl-x cl-x)) (progn (and (memq (type-of cl-x) cl-struct-jupyter-session-tags) t))) (signal 'wrong-type-argument (list 'jupyter-session cl-x))) (aref cl-x 2))))) (jupyter-start channel :identity identity)) (list 'start-channel (eieio-oref channel 'type))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd))))) ((eq x37 'timer) (let ((x57 (cdr-safe cmd))) (if (consp x57) (let ((x58 (car-safe x57)) (x59 (cdr-safe x57))) (if (consp x59) (let ((x60 (car-safe x59)) (x61 (cdr-safe x59))) (if (consp x61) (let ((x62 (car-safe x61)) (x63 (cdr-safe x61))) (if (null x63) (let ((id x58) (period x60) (cb x62)) (prog1 nil (let ((timer (run-at-time 0.0 period (byte-compile cb)))) (puthash id timer jupyter-ioloop-timers)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd))))) ((eq x37 'callback) (let ((x64 (cdr-safe cmd))) (if (consp x64) (let ((x65 (car-safe x64)) (x66 (cdr-safe x64))) (if (null x66) (let ((cb x65)) (prog1 nil (setq jupyter-ioloop-timeout 0) (add-hook 'jupyter-ioloop-pre-hook (byte-compile cb) 'append))) (let nil (error "Unhandled command %s" cmd)))) (let nil (error "Unhandled command %s" cmd))))) ((eq x37 'quit) (let ((x67 (cdr-safe cmd))) (if (null x67) (let nil (signal 'quit nil)) (let nil (error "Unhandled command %s" cmd))))) (t (let nil (error "Unhandled command %s" cmd))))) (let nil (error "Unhandled command %s" cmd))))) (if (and res (listp res)) (progn (zmq-prin1 res)))))))) (while t (run-hooks 'jupyter-ioloop-pre-hook) (setq events (condition-case nil (zmq-poller-wait-all jupyter-ioloop-poller jupyter-ioloop-nsockets jupyter-ioloop-timeout) ((zmq-EAGAIN zmq-EINTR zmq-ETIMEDOUT) nil))) (let ((stdin-event (zmq-assoc jupyter-ioloop-stdin events))) (if stdin-event (progn (setq events (delq stdin-event events)) (funcall on-stdin)))) (run-hook-with-args 'jupyter-ioloop-post-hook events)))) (quit (mapc #'jupyter-stop jupyter-channel-ioloop-channels) (zmq-prin1 '(quit)))))) nil])

Any ideas?

mk0417 commented 1 week ago

It should be due to the the new commit of Emacs 30. Similar issue here: https://github.com/emacs-jupyter/jupyter/issues/540

danielpopescu commented 1 week ago

Thank you!

If I turn zmq off with (setq jupyter-use-zmq nil)

then I get this (on macos, on linux it works fine):

Launching notebook process on port 8888...done progn: Jupyter REST API error: 404, "Not found"

Any ideas? Ty

danielpopescu commented 1 week ago

btw, https://github.com/emacs-mirror/emacs/commit/f2bccae22bd47a2e7e0937b78ea06131711b935a is probably not going away.. so emacs-zmq might need to be fixed to work with this change?

danielpopescu commented 1 week ago

Thank you!

If I turn zmq off with (setq jupyter-use-zmq nil)

then I get this (on macos, on linux it works fine):

Launching notebook process on port 8888...done progn: Jupyter REST API error: 404, "Not found"

Any ideas? Ty

It appears that emacs jupyter doesn't work with jupyter_server >= 2.x release.... Maybe this API change is causing the issue https://github.com/jupyter-server/jupyter_server/pull/1047 ?

singletS commented 1 week ago

I'm also getting "Error in ZMQ subprocess: wrong-type-argument" on linux (debian) GNU Emacs 30.0.50 Development version 57c0549 which pre-dates commit f2bccae by a couple months. This setup used to work fine, but after an update of several melpa/elpa packages now no longer works. Org 9.6.15, juypter-server 2.14.0, emacs-zmq 1.0.0.

nnicandro commented 1 week ago

I believe I have found a fix for the wrong-type-argument error caused by f2bccae which I will push to emacs-zmq when I get the chance.

@danielpopescu As for the REST API error, there may be more information in the notebook buffer. Could you list here the contents of the *jupyter-notebook* buffer that gets created when you specify jupyter-use-zmq to nil.

gmoutso commented 1 day ago

@danielpopescu I also had a 404 error once on a remote jupyter server I was using (that had password and token disabled). I don't remember the details but it was related to http://jupyterserver:port/login missing when jupyter-api-request-xsrf-cookie was called. I found this by looking at the log of the jupyter server. I solved it like this:

(defun gm/jupyter-api-request-xsrf-cookie-error-advice (func &rest args)
  (condition-case nil
      (apply func args)
    (jupyter-api-http-error nil)))
(advice-add 'jupyter-api-request-xsrf-cookie :around #'gm/jupyter-api-request-xsrf-cookie-error-advice)