-
Notifications
You must be signed in to change notification settings - Fork 85
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
Unexpected failure mode for dispatch="ui"
when there is no UI
#1732
Comments
Presumably there is a similar issue with traits/traits/trait_notifiers.py Lines 617 to 621 in 92ecd7e
|
Drive-by note: Agreed that there should be a clear failure message if we're not on the main thread and there's no ui. And yes, I suppose we should just ignore |
Hi, I think the second exception may have already been solved by the latest pyface:
But the first error remains:
Environment: Python3.11, MacOS attrdict 2.0.1 [notice] A new release of pip available: 22.3.1 -> 23.1 |
After some testing, I found the first error from Corran will resolve if the main thread check in the ui_dispatch is changed to the following:
Then the code will run successfully:
So is the dispatch supposed to run when there is no ui but on the main thread? |
Yes, I think that's probably the right behaviour here. |
OK, I will create a PR for this change then |
) Previously the ui_dispatch(handler, *args, **kw) function in traits/traits/trait_notifiers.py only checks current_thread().ident with ui_thread. But supposedly, this current thread id should be compared with the main thread (threading.main_thread()). This discrepancy caused a no ui failure in ui dispatch as mentioned in issue #1732. This PR attempts to resolve this failure. Closes #1732 **Checklist** - [ ] Tests - [x] Update API reference (`docs/source/traits_api_reference`) (seems no need to change for this PR) - [ ] Update User manual (`docs/source/traits_user_manual`) (seems no need to change for this PR) - [x] Update type annotation hints in stub files (seems no need to change for this PR) --------- Co-authored-by: Chengyu Liu <cyliu@aus552cyliu.local> Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
When using
dispatch="ui"
and there is no UI (in particular, Pyface has not done toolkit selection), the dispatcher fails with an attempt to callNone
as the handler:This also happens when the Pyface toolkit is
null
(which may be a Pyface bug):I'm not entirely sure what the correct behaviour is here.
I think I would expect dispatch to work if the current thread is the main thread, given the short-circuit in the code here:
traits/traits/trait_notifiers.py
Lines 46 to 50 in 92ecd7e
But given there is no way to dispatch something back to the main thread if there is no event loop around, I'd expect at least a better failure message if the dispatch is not on the main thread.
The text was updated successfully, but these errors were encountered: