ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Output widget does not capture print under IPython's `%%capture` magic

Open asaboor-gh opened this issue 1 year ago • 0 comments

It might be a silly use case, but I noticed that if we are using Output widget under IPython's %%capture magic or capture_output contextmanger, it cannot capture print which goes on top level IPython capture only.

from IPython.utils.capture import capture_output
from ipywidgets import Output

out = Output()

with capture_output() as cap: # could be %%capture cap
    print("1. In main capture")

    with out:
        print("2. Still in main capture")
        display("3. In Output widget")

    print('4. before displaying out')
    display(out) # only display will be shown here but at end
    print('5. after displaying out')

cap.show()

image

It seems like Output is not able to acquire some kind of system display hooks. This also results in unordered output.

asaboor-gh avatar Mar 09 '24 16:03 asaboor-gh