Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the background thread's ouput will append to last active cell's output, not the actual corresponding cell? #14925

Closed
potoo0 opened this issue Aug 7, 2023 · 1 comment
Labels
bug status:Answered The issue has been answered by a community member. status:Needs Triage Applied to new issues that need triage

Comments

@potoo0
Copy link

potoo0 commented Aug 7, 2023

Description

the background thread's ouput will append to last active cell's output,

Reproduce

# cell1
from threading import Thread, current_thread
from time import sleep


def task():
    cnt = 3
    while cnt:
        print(f'task(cnt={cnt}) {current_thread()}')
        cnt -= 1
        sleep(1)

# cell2
Thread(target=task, name='t1').start();
# cell2 output
'''
task(cnt=3) <Thread(t1, started 140546848823040)>
''';

# cell3
Thread(target=task, name='t2').start();
# cell3 output
'''
task(cnt=3) <Thread(t2, started 140546857215744)>
task(cnt=2) <Thread(t1, started 140546848823040)>
task(cnt=2) <Thread(t2, started 140546857215744)>
task(cnt=1) <Thread(t1, started 140546848823040)>
task(cnt=1) <Thread(t2, started 140546857215744)>
''';

jupyterlab thread's output

@potoo0 potoo0 added the bug label Aug 7, 2023
@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Aug 7, 2023
@JasonWeill
Copy link
Contributor

This behavior may be by design. When a Jupyter notebook runs a cell, the cell runs to completion (you can see when [*] turns into a number like [2]). When future cells run, output is captured for their cell. Cells do not run in isolation from each other, and two cells don't run simultaneously, as far as I've observed.

@JasonWeill JasonWeill added the status:Answered The issue has been answered by a community member. label Aug 8, 2023
@potoo0 potoo0 closed this as completed Aug 10, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug status:Answered The issue has been answered by a community member. status:Needs Triage Applied to new issues that need triage
Projects
None yet
Development

No branches or pull requests

2 participants