You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New hook point for messages / message transforms. #113
Also, there are issues with threading. Since the ZMQDisplayPublisher is a global object, installing a message filter there naively will affect messages from everywhere. In the case of a context manager, it seems that the "correct" behavior is to only have the output from the block of code in the current thread. @minrk suggested making the hooks thread local attributes in the ZMQDisplayPublisher object (see https://docs.python.org/2/library/threading.html#threading.local), maybe something like
Yup, that should be right. Also to clarify, implementing this hook should need no changes in any other repos, but the intention is to use it in a new implementation of the OutputWidget downstream.
We can get a handle on the display publisher with get_ipython().display_pub
Make a context manager that will register a hook and store a list of display outputs. You may need to flush something when exiting the context manager to make sure you get all of the display messages.
Make a widget that has such a context manager. It should take over any display_pub messages and store the messages in a list as its synced widget state. A clear_output message should clear the message queue (and probably doesn't need to be sent, since the empty message queue will be synced).
Make a front end widget that will render the display pub message queue (this will likely involve using a rendermime instance that is passed in...)
@minrk - can you remind us what needs to be done for capturing stdout/stderr?
Just checking, the hook unregisters itself when the context manager exits, right? (that's not illustrated in your screenshot, but it should work that way)
For stdout/err, the simple thing is to swap out sys.stdout/err to an io.StringIO object, but that won't have the same threadlocal behavior the hooks now have. To preserve that, some amount of threadlocal things will need to be added to the IOStream code, so that writes go to the short-circuit buffer rather than the default.
I think this issue is solved with #115. Let's document the widget work on an issue in the ipywidgets repo. @dwillmer, can you open a work-in-progress PR over there?
Activity
jasongrout commentedon Mar 24, 2016
Also, there are issues with threading. Since the ZMQDisplayPublisher is a global object, installing a message filter there naively will affect messages from everywhere. In the case of a context manager, it seems that the "correct" behavior is to only have the output from the block of code in the current thread. @minrk suggested making the hooks thread local attributes in the ZMQDisplayPublisher object (see https://docs.python.org/2/library/threading.html#threading.local), maybe something like
jasongrout commentedon Mar 24, 2016
Code to touch for making a display hook registration system includes the following.
@minrk, can you verify this is right?
jasongrout commentedon Mar 24, 2016
Interestingly, since clear_output is implemented by just sending a clear_output message to the front end, this works too:
minrk commentedon Mar 24, 2016
Yup, that should be right. Also to clarify, implementing this hook should need no changes in any other repos, but the intention is to use it in a new implementation of the OutputWidget downstream.
jasongrout commentedon Apr 5, 2016
@dwillmer, @minrk: next steps:
We can get a handle on the display publisher with
get_ipython().display_pub@minrk - can you remind us what needs to be done for capturing stdout/stderr?
dwillmer commentedon Apr 7, 2016
@jasongrout - is this ^^ what you're expecting?
The
printcalls go to the normal output area, but anydisplay_datamessages within the new context manager are sent to the custom widget area.Clearly we'll change the name from
MessageWidget;) just wanted some early feedback!jasongrout commentedon Apr 7, 2016
Yep, that's the idea. Thanks!
Things to still do:
And when I finish the widgets in the new notebook, actually render the messages sent to the message widget.
jasongrout commentedon Apr 7, 2016
Just checking, the hook unregisters itself when the context manager exits, right? (that's not illustrated in your screenshot, but it should work that way)
dwillmer commentedon Apr 7, 2016
yep, it does, i'll post an updated screenshot in a bit.
minrk commentedon Apr 7, 2016
For stdout/err, the simple thing is to swap out
sys.stdout/errto anio.StringIOobject, but that won't have the same threadlocal behavior the hooks now have. To preserve that, some amount of threadlocal things will need to be added to the IOStream code, so that writes go to the short-circuit buffer rather than the default.jasongrout commentedon Apr 7, 2016
@dwillmer - no need to post a new screenshot for the exit status. I trust it's there.
dwillmer commentedon Apr 23, 2016
Update:
with widget.capture():instead of 'with widget:`.capture()takes an optional positional arg for the message type, so you can intercept different messages in each context.jasongrout commentedon Apr 23, 2016
I think this issue is solved with #115. Let's document the widget work on an issue in the ipywidgets repo. @dwillmer, can you open a work-in-progress PR over there?
jasongrout commentedon Apr 23, 2016
@minrk or @dwillmer, if this issue is solved by #115, can you close this? Apparently I don't have permissions to close issues on this repo.