ipywidgets
ipywidgets copied to clipboard
Output widget does not capture print under IPython's `%%capture` magic
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()
It seems like Output is not able to acquire some kind of system display hooks. This also results in unordered output.