[IPython-dev] threadsafe widgets
Loper, Jackson
jackson_loper at brown.edu
Thu Jan 8 22:28:03 EST 2015
It is my understanding that the traitlets in most ipython notebook widgets
aren't threadsafe. If you're not sure what I mean, I attached a small
example at the bottom of this note.
What's the best way for me to make a threadsafe widget? I could inherit
from DOMWidget and override a whole bunch of methods with a wrapper that
puts things inside a threading.Lock, but it seems kinda like overkill. I
suppose theoretically you could lock all the traitlets & comms calls, but
that also seems like overkill. Or maybe not...I have no sense of
proportion for these things.
The application is straightforward, maybe there's an easier way to do it.
I'd like to be able to edit files from jupyterhub's host directly inside
the notebook; CodeMirror is much more responsive than vim over ssh. It was
easy to make a text-editing widget based on codemirror, but I'd like to pop
up a CodeMirror.dialog if somebody has changed the file being edited.
Can't figure out how to do that in a threadsafe way.
Happy Thursday!
Jackson Loper
Pattern Theory Group
Division of Applied Math
Brown University
====== threadsome danger =====
Running the latest github clone of jupyterhub, code like this is a very bad
idea:
import IPython.display
from IPython.html import widgets, nbextensions
import threading
from numpy.random import randint
isw=widgets.IntSlider()
IPython.display.display(isw)
def randoset(N):
for i in range(N):
isw.value=randint(0,50)
t1=threading.Thread(target=randoset,args=[100])
t2=threading.Thread(target=randoset,args=[100])
t1.start()
t2.start()
The jupyterhub logs errors such as
Malformed message: [b'comm-....', b'<IDS|MSG>', b'comm-...', b'<IDS|MSG>',
... more stuff.. ]
Presumably two attempts at sending data over comms got mixeduptogether
here, which is why we ended up with two <IDS_MSG> in one message!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150108/e7edef5e/attachment.html>
More information about the IPython-dev
mailing list