-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Fix test_print_to_correct_cell_from_child_thread #1312
base: main
Are you sure you want to change the base?
Conversation
tests/test_kernel.py
Outdated
Thread(target=child_target).start() | ||
sleep({interval * iterations}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also work if in addition to this sleep you keep the sleep({interval})
above? I wonder if that was here for a reason. In other words, I think that adding the sleep at the end is fine, I am less confident about the function of the sleep that was removed (as this can change some edge case related to execution order).
Further, should we save a reference to the thread in a local variable before calling sleep()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 41b31c5 I added back the first sleep
, and replaced the other sleep
with a thread.join()
, since it's essentially the same.
I think also related to this is #1289 . Most of the time, in my experience, routing output to the cell that happened to spawn the thread not the right thing to do, and results in quite a bit of mysteriously lost and out-of-order output. |
Thanks for linking #1289, I missed it when it was opened (despite the mention!). I see your point. I think that usually routing to the spawning cell is the right thing to do, but will happily agree that there should be a way to opt out for the scenarios that you present. |
Failure is unrelated:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The parent thread has to live for the duration of the child thread, otherwise the parent thread exits before the child thread and disappears from the active threads, causing it to be removed from
thread_to_parent
and eventually leading to messages not being routed to the right cell:ipykernel/ipykernel/ipkernel.py
Lines 781 to 794 in 41a965e
@krassowski Could you confirm? I saw that while working on #1291.