Skip to content

Commit 8ce63f6

Browse files
committed
workaround for absence of comm_list_[request/reply]
1 parent 64fdf68 commit 8ce63f6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ipywidgets/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55
ip = get_ipython()
66
if ip is not None and hasattr(ip, 'kernel') and hasattr(ip.kernel, 'comm_manager'):
77
ip.kernel.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened)
8+
9+
# Workaround for the absence ofa comm_list_[request/reply] shell message
10+
class CommList(Widget):
11+
"""CommList widgets are is typically instantiated by the front-end. As soon as it is instantiated, it sends the list of valid comms, and kills itself. It is a *very dumb* workaround to the absence of comm_list shell message."""
12+
13+
def __init__(self, **kwargs):
14+
super(CommList, self).__init__(**kwargs)
15+
self.send(dict(comm_list=list(self.comm.kernel.comm_manager.comms.keys())))
16+
self.close()
17+

ipywidgets/static/widgets/js/manager.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,28 @@ define([
495495
/**
496496
* Gets a promise for the list of comms open in the backend
497497
*/
498-
var that = this;
498+
499+
// Version using the comm_list_[request/reply] shell message.
500+
/*var that = this;
499501
return new Promise(function(resolve, reject) {
500502
that.comm_manager.kernel.comm_list(function(msg) {
501503
resolve(msg['content']['comm_list']);
502504
});
505+
});*/
506+
507+
// Workaround for absence of comm_list_[request/reply] shell message.
508+
// Create a new widget that gives the comm list and commits suicide.
509+
var that = this;
510+
return new Promise(function(resolve, reject) {
511+
comm = that.comm_manager.new_comm('ipython.widget',
512+
{'widget_class': 'ipywidgets.CommList'},
513+
'comm_list');
514+
comm.on_msg(function(msg) {
515+
var data = msg.content.data;
516+
if (data.content && data.method === 'custom') {
517+
resolve(data.content.comm_list);
518+
}
519+
});
503520
});
504521
};
505522

0 commit comments

Comments
 (0)