Skip to content

Commit ba58788

Browse files
committed
Tolerate multiple ZMQ identities
1 parent ca0abde commit ba58788

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

lib/kernel.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Kernel {
5050
}
5151
}
5252

53-
// uuid, delim, hmac, header, parent_header, metadata, content
53+
// uuids, delim, hmac, header, parent_header, metadata, content
5454
onShell() {
5555
const strs = [].map.call(arguments, a => a.toString())
5656
let i
@@ -59,34 +59,33 @@ export default class Kernel {
5959
break
6060
}
6161
}
62-
const idents = [].slice.call(arguments, 0, i)
62+
const uuids = [].slice.call(arguments, 0, i)
6363
const args = strs.slice(i + 2)
64-
const uuid = idents[idents.length - 1]
6564
let [header, parent_header, metadata, content] = args
6665

6766
header = JSON.parse(header)
6867
if (header.msg_type === 'kernel_info_request') {
69-
this.send('shell', uuid, 'kernel_info_reply', info, header)
68+
this.send('shell', uuids, 'kernel_info_reply', info, header)
7069
return
7170
}
7271
if (header.msg_type === 'history_request') {
73-
this.send('shell', uuid, 'history_reply', {history: []}, header)
72+
this.send('shell', uuids, 'history_reply', {history: []}, header)
7473
return
7574
}
7675

7776
metadata = JSON.parse(metadata)
7877
content = JSON.parse(content)
7978
if (header.msg_type === 'execute_request') {
80-
this.executeRequest(uuid, header, metadata, content)
79+
this.executeRequest(uuids, header, metadata, content)
8180
return
8281
}
8382
if (header.msg_type === 'complete_request') {
84-
this.completeRequest(uuid, header, metadata, content)
83+
this.completeRequest(uuids, header, metadata, content)
8584
return
8685
}
8786
if (header.msg_type === 'shutdown_request') {
8887
this.ctx.shutdown()
89-
this.send('shell', uuid, 'shutdown_response', content, header)
88+
this.send('shell', uuids, 'shutdown_response', content, header)
9089
return
9190
}
9291
console.log('Unknown message type: ', header.msg_type)
@@ -96,18 +95,18 @@ export default class Kernel {
9695
}
9796

9897
ioPub(msg_type, content, parent) {
99-
this.send('iopub', get_uuid(), msg_type, content, parent)
98+
this.send('iopub', [get_uuid()], msg_type, content, parent)
10099
}
101100

102-
completeRequest(uuid, header, metadata, content) {
101+
completeRequest(uuids, header, metadata, content) {
103102
this.ctx.complete(content.code, content.cursor_pos, metadata.variant, (error, completions) => {
104103
if (error) {
105104
console.log(error)
106-
return this.send('shell', uuid, 'complete_reply', {
105+
return this.send('shell', uuids, 'complete_reply', {
107106
status: 'err'
108107
}, header)
109108
}
110-
this.send('shell', uuid, 'complete_reply', completions, header)
109+
this.send('shell', uuids, 'complete_reply', completions, header)
111110
})
112111
}
113112

@@ -134,7 +133,7 @@ export default class Kernel {
134133
}, header)
135134
}
136135

137-
executeRequest(uuid, header, metadata, content) {
136+
executeRequest(uuids, header, metadata, content) {
138137
this.ioPub('status', {execution_state: 'busy'}, header)
139138
this.count += 1
140139
this.ioPub('execute_input', {
@@ -152,7 +151,7 @@ export default class Kernel {
152151
evalue: error.message,
153152
traceback: [error.stack],
154153
}, header)
155-
this.send('shell', uuid, 'execute_reply', {
154+
this.send('shell', uuids, 'execute_reply', {
156155
status: 'error',
157156
ename: 'Runtime error',
158157
evalue: error.message,
@@ -170,7 +169,7 @@ export default class Kernel {
170169
data: result,
171170
}, header)
172171
}
173-
this.send('shell', uuid, 'execute_reply', {
172+
this.send('shell', uuids, 'execute_reply', {
174173
status: 'ok',
175174
execution_count: this.count,
176175
user_expressions: {},
@@ -201,14 +200,14 @@ export default class Kernel {
201200
return res
202201
}
203202

204-
_send(sock, id, header, parent, metadata, content) {
203+
_send(sock, ids, header, parent, metadata, content) {
205204
const toHash = [
206205
json(header),
207206
json(parent),
208207
json(metadata || {}),
209208
json(content)]
210209
const hmac = this.hash(toHash.join(''))
211-
const data = [id, DELIM, hmac].concat(toHash)
210+
const data = ids.concat([DELIM, hmac]).concat(toHash)
212211
this.sockets[sock].send(data)
213212
}
214213
}
@@ -220,4 +219,3 @@ function fixUnicode(val) {
220219
function json(data) {
221220
return fixUnicode(JSON.stringify(data))
222221
}
223-

0 commit comments

Comments
 (0)