Commit 5093a6ea authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

kernels: Catch EINTR on 'zmq-poll' calls.

* jupyter/kernels.scm (EINTR-safe): New procedure.
(read-message): Use it.
parent baaad11b
......@@ -326,6 +326,25 @@ its client."
;; Communicating with a kernel.
(define (EINTR-safe proc)
"Return a variant of PROC that catches EINTR 'zmq-error' exceptions and
retries a call to PROC."
(define (safe . args)
(catch 'zmq-error
(lambda ()
(apply proc args))
(lambda (key errno . rest)
(if (= errno EINTR)
(apply safe args)
(apply throw key errno rest)))))
(define zmq-poll*
;; XXX: As of guile-simple-zmq commit 878f6dc (Nov. 2018), 'zmq-poll'
;; doesn't catch EINTR, so do it here.
(EINTR-safe zmq-poll))
(define* (read-message kernel #:optional (timeout -1))
"Read one message from one of the sockets of KERNEL and return it. If the
message is a \"regular\" JSON message, return it as an alist; if it's a
......@@ -337,10 +356,10 @@ milliseconds. If TIMEOUT expires before a message has been received, return
(define shell (kernel-shell kernel))
(define iopub (kernel-iopub kernel))
(define items
(zmq-poll (map (lambda (socket)
(poll-item socket (logior ZMQ_POLLIN ZMQ_POLLERR)))
(kernel-sockets kernel))
(zmq-poll* (map (lambda (socket)
(poll-item socket (logior ZMQ_POLLIN ZMQ_POLLERR)))
(kernel-sockets kernel))
(let loop ((items items))
(match items
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment