-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: add main thread check for ui dispatch, solve no ui failure (#1740
) 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 <[email protected]> Co-authored-by: Mark Dickinson <[email protected]>
- Loading branch information
1 parent
60f918e
commit 872def3
Showing
3 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX | ||
# All rights reserved. | ||
# | ||
# This software is provided without warranty under the terms of the BSD | ||
# license included in LICENSE.txt and may be redistributed only under | ||
# the conditions described in the aforementioned license. The license | ||
# is also available online at http://www.enthought.com/licenses/BSD.txt | ||
# | ||
# Thanks for using Enthought open source! | ||
|
||
import unittest | ||
|
||
from traits.api import HasTraits, Int | ||
|
||
|
||
class TestTraitNotifiers(unittest.TestCase): | ||
def test_ui_dispatch(self): | ||
# Given | ||
class DispatchTest(HasTraits): | ||
test_param = Int() | ||
|
||
t = DispatchTest() | ||
|
||
event_list = [] | ||
|
||
# create handler | ||
def test_handler(event): | ||
event_list.append(event) | ||
|
||
# When | ||
t.observe(test_handler, "test_param", dispatch="ui") | ||
t.test_param = 1 | ||
|
||
# Then | ||
# check the observer is called once | ||
self.assertEqual(len(event_list), 1) | ||
# check the name of the parameter change | ||
self.assertEqual(event_list[0].name, "test_param") | ||
# check whether the value starts at 0 | ||
self.assertEqual(event_list[0].old, 0) | ||
# check whether the value has been set to 1 | ||
self.assertEqual(event_list[0].new, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters