[IPython-dev] threadsafe widgets
jackson_loper at brown.edu
Fri Jan 9 17:59:39 EST 2015
Ah, the threading situation seems to be more diresome than I thought. I
believe the following code is unsafe to run.
=== Problem code ===
from IPython.html import widgets
from numpy.random import randint
for i in range(N):
This code produces malformed message errors for me in the jupyterhub
I believe this is because all widgets seem to share the same iopub_socket
and write to it whenever the user changes a traitlet. And of course zmq
sockets aren't threadsafe.
=== A few potential solutions ===
1) "Quick" -- Wrap iopub_socket in a threadsafe wrapper. Surround every
important function call in a mutex.
2) "Hintjens-approved" -- Give every single widget its own inproc PUB
socket. We'd have to spin up an extra thread (or a greenlet in some
pre-extant thread? I don't really understand what the different IPython
threads do...but I could find out...) with a SUB socket to collect them all
together and forward them all out on iopub_socket.
3) "Dirty" -- Wrap IPython.kernel.zmq.session.Session.send inside a mutex.
Are there use-cases where anybody besides Session actually does anything
=== Motivation ===
I think there could be valid use-cases for widgets which display results
from polling external resources, e.g. widgets which keep track of EC2
instances, widgets which monitor IPython.parallel workerbees, etc.
=== Conclusion ===
I'd be happy to attack this problem, if you guys think it would be useful.
If so, let me know what would be a good general direction, and I'll put
together a pull request.
Pattern Theory Group
Division of Applied Math
PS. I love the new text editor feature in the ipython master branch! My
days of vim-over-ssh aren't over yet (NERDTree and push-notification of
filechange detection are still too useful to me when logging on from
multiple machines) but I can see the end in sight!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev