Skip to content

Output widget context manager prints to wrong cell (if used in a Thread) #2358

@soerenwolfers

Description

@soerenwolfers

If I wrap this code from source/docs/examples/Output Widget.ipynb,

import ipywidgets as widgets
out = widgets.Output(layout={'border': '1px solid black'})
with out:
    for i in range(10):
        print(i, 'Hello world!')

in a Thread,

import ipywidgets as widgets
out = widgets.Output(layout={'border': '1px solid black'})
def foo():
    with out:
        for i in range(10):
            print(i,'Hello world!')
IPython.display.display(out)
threading.Thread(target=foo).start()

then the output ends up in a wrong cell as soon as I execute another cell.

I would consider this a bug, as I cannot imagine anyone wanting the Output widget to change cells. To convince you of the awesomeness of updating the Output widget in the cell where it was started, imagine how easy it would be to make a simple

%%run_cell_in_background
for i in range(10):
        print(i, 'Hello world!')

out of this (indeed, that's what I did, and it works beautifully except for the problem above. In my application, I need a simple job monitor, but I am sure there would be dozens of different uses for this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions