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

Convert dynamic on_trait_change uses to observe #870

Merged
merged 34 commits into from
Feb 1, 2021

Conversation

aaronayres35
Copy link
Contributor

@aaronayres35 aaronayres35 commented Jan 25, 2021

part of #732 and #637

@aaronayres35
Copy link
Contributor Author

Im currently getting a strange segfault I am trying to debug. Somehow adding print(handler) directly above this line https://github.com/enthought/traits/blob/743531b45fa7321ede9b2009b1dcee47ed0172a4/traits/observation/_observer_change_notifier.py#L85
prevents the segfault (but tests still error)

action.observe(self._on_action_enabled_changed, "enabled", remove=True)
action.observe(self._on_action_visible_changed, "visible", remove=True)
action.observe(self._on_action_checked_changed, "checked", remove=True)
action.observe(self._on_action_name_changed, "name", remove=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason we don't remove the listener for "image" here...? I left code to match it as is but this feels like a bug? Additionally for some of the occurrences below, we do not remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for future ref: Maybe the segfault was related to this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, definitely should be removing anything that is added.

""" Called when the selection in the tree is changed. """

selection = event.new
if len(selection) > 0:
self._table_viewer.input = selection[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This example seems to not be run-able on qt or wx. I will look if there is already an issue and open one if not.

self._manager.observe(self._on_enabled_changed, "enabled")
self._manager.observe(self._on_visible_changed, "visible")
self._manager.observe(self._on_name_changed, "name")
self._manager.observe(self._on_image_changed, "image")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The manager/its subclasses do not explicitly define an "image" trait

@aaronayres35
Copy link
Contributor Author

I reverted the changes to menu_manager.py for now as I do not understand/want to deal with the segfault in this PR. The segfault was occurring in test_action_item.py. This PR does make changes to action_item.py, and I'm uncertain if they were related to the segfault. I don't believe they are and thus am leaving those changes in this PR (Tests should all still be passing). However, if a reviewer sees something I am not please make it known.

Also, looking at this PR in its current state, it is already getting decently large so I am tempted to just arbitrarily stop here and flag it for review... Then I will leave the remaining changes for a second PR.
Maybe I will go through and look for any other very simply updates that can be made to tack on here.

@aaronayres35
Copy link
Contributor Author

Aha! looks like segfault is still occurring on CI, but I no longer am able to reproduce locally. I suspect the changes in action_item.py are responsible. I will revert that commit for this PR as well and investigate later on

@aaronayres35 aaronayres35 reopened this Jan 27, 2021
@aaronayres35 aaronayres35 changed the title [WIP]Convert dynamic OTC uses to observe Convert dynamic OTC uses to observe Jan 27, 2021
Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

LGTM with a bunch of style recommendations.

examples/grid.py Outdated Show resolved Hide resolved
examples/node_tree.py Outdated Show resolved Hide resolved
examples/tree.py Outdated Show resolved Hide resolved
examples/tree_viewer.py Outdated Show resolved Hide resolved
pyface/ui/wx/wizard/wizard.py Outdated Show resolved Hide resolved
pyface/wizard/chained_wizard_controller.py Outdated Show resolved Hide resolved
pyface/wizard/chained_wizard_controller.py Outdated Show resolved Hide resolved
pyface/wizard/i_wizard.py Outdated Show resolved Hide resolved
pyface/wizard/wizard_controller.py Outdated Show resolved Hide resolved
@aaronayres35
Copy link
Contributor Author

ref: #876

@aaronayres35
Copy link
Contributor Author

Latest round of changes has CI failing. Looking into all the places where we need to explicitly pass event=None now specifically at timers and their callbacks

@aaronayres35
Copy link
Contributor Author

aaronayres35 commented Feb 1, 2021

@rahulporuri I tried to fix the CI failures in the latest commit 🤞 . However, the fixes seem very fragile, and I am not confident I didn't miss anything. We may be introducing bugs that are flying under the radar because they are not covered in tests. In other words, in the latest commit, I was trying to identify any ways that handler.callback could be called so I could make sure it always was called with the correct event=None passed in. I believe CI should pass on this commit now / that I have found the ones related to CI failures but I am uncertain I have found all of them.

I understand style wise we want to go with just passing event, but it seems to me we need to make sure we aren't risking any bugs... If instead of all the changes in the latest commit I simply have the ConditionHandler's callback method specify event=None as a kwarg, CI will also pass and I am more confident existing code will not break...

What are your thoughts about this?

EDIT: see latest commit, where I just went ahead and did the "refactor" approach. I think this is probably the go here and in general. The only thing to note: when we do the refactor approach we will probably want to try to leave the current handler with the same name without any arguments as a standard method and then redefine a new handler that we then observe that has the event arg. This is because we may not always be certain of all the code paths that could be taken to call the handler standalone, but we will know where it is explicitly called with observe. Maybe thats not entirely true... In any case we need to be cautious to not break things!

Comment on lines 202 to 204
timer = CallbackTimer(
callback=handler.callback, kwargs={'event': None}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

it is better to simply update the ConditionHandler.callback method to set event=None instead of updating all of the callers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me, should I do it where I simply have event=None as a kwarg on callback then? Or is the most recent solution with _callback better?

I think just having it as a kwarg makes the most sense to me

Copy link
Contributor

Choose a reason for hiding this comment

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

I think just having it as a kwarg makes the most sense to me

Let's go with that approach - instead of the refactor.

@rahulporuri rahulporuri changed the title Convert dynamic OTC uses to observe Convert dynamic on_trait_change uses to observe Feb 1, 2021
@aaronayres35
Copy link
Contributor Author

aaronayres35 commented Feb 1, 2021

@rahulporuri I was thinking of looking into making sure we remove and listeners we set up before we push this through. Should I do that, or make those fixes in a separate PR (since they didn't exist with otc before, so this PR should preserve behavior, but ultimately we will want them addressed).
I am fine either way, if you want me to try and tack those changes onto this PR, or just push this through and do them separately (in the second case I will be sure to open a new issue as well)

EDIT: on second thought I think I will do this separately. Many (most?/all?) of the cases are such that the code is transient, e.g. examples, and some tests. Still worth looking into, but I think I will leave them for a separate issue/PR

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

still LGTM, assuming CI is happy

@aaronayres35 aaronayres35 merged commit 254a3ae into master Feb 1, 2021
@aaronayres35 aaronayres35 deleted the replace-dynamic-otc-observe-simple branch February 1, 2021 17:37
@rahulporuri
Copy link
Contributor

EDIT: on second thought I think I will do this separately. Many (most?/all?) of the cases are such that the code is transient, e.g. examples, and some tests. Still worth looking into, but I think I will leave them for a separate issue/PR

that's fine by me but do open an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants