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

MAINT: add main thread check for ui dispatch, solve no ui failure #1740

Merged
merged 18 commits into from
Apr 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion traits/trait_notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def set_ui_handler(handler):


def ui_dispatch(handler, *args, **kw):
if threading.current_thread().ident == ui_thread:
if threading.current_thread().ident == threading.main_thread().ident:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the .ident here: you can just compare the thread objects directly.

Suggested change
if threading.current_thread().ident == threading.main_thread().ident:
if threading.current_thread() == threading.main_thread():

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. Are directly comparing threads vs comparing their ids completely equivalent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yes. The == check is essentially an is check (there's no __eq__ special method created), and there should be exactly one Thread object per OS thread.

handler(*args, **kw)
else:
ui_handler(handler, *args, **kw)
Expand Down