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

Ensure all watchers are executed in scheduling order #323

Merged
merged 5 commits into from
Mar 8, 2019

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 8, 2019

Fixes #322

  • Add tests

@philippjfr
Copy link
Member Author

One way to make this PR cleaner would be to add a context manager for setting and unsetting the BATCH_WATCH flag.

@philippjfr philippjfr force-pushed the batch_watch_ordered branch from a4e9c7d to dca2a62 Compare March 8, 2019 12:40
@philippjfr
Copy link
Member Author

Ready to review/merge.

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

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

I can't follow the logic, but from the discussion it sounds like the right approach.

param/parameterized.py Outdated Show resolved Hide resolved
@@ -1215,6 +1238,7 @@ def set_param(self_, *args,**kwargs):
positional arguments, but the keyword interface is preferred
because it is more compact and can set multiple values.
"""
BATCH_WATCH = self_.self_or_cls.param._BATCH_WATCH
Copy link
Member

Choose a reason for hiding this comment

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

Why the scary capitals?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just following the style of the original variable name, not sure it has to be capitalized but if we decide to change I would change it everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

As you wish.

@martindurant
Copy link

Quick question on this: does the watcher get the event itself in its arguments? I would say, that an event which is going to cause another like event of a different value to be spawned should explicitly set the event to be ignored downstream. That way, if you want a "less than 4" filter on an element as you described, other watchers never see the value 5, even temporarily. This leaves it up to the programmer to think about whether it makes sense for an event to propagate or not.
(This is a separate concept from batching events as above)

@philippjfr
Copy link
Member Author

philippjfr commented Mar 8, 2019

Quick question on this: does the watcher get the event itself in its arguments?

Yes it does, and I agree with you. I think a watcher should be able to invalidate an event it receives so that downstream watchers never see it. That said maybe a better solution would be to offer a way to define preprocessors on parameters so the value is validated (or in this case clipped) before it is set and triggers downstream events. I can't quite envision if there are other scenarios where you might want a watcher to invalidate an event it receives.

@martindurant
Copy link

to offer a way to define preprocessors on parameters so the value is validated before it is set

This way means having a different type of watcher, which may be confusing. I suppose it could be a very simple function valid(val) -> True/False.

I can imagine scenarios, such as the new value caused a procedure to fire which failed, so it is OK to set that value (it's not invalid, only failing at the current moment and set of other values) but follow-on procedures should not run. You could argue this case is moot, any follow-ons should respond the a change in a separate output area...

@philippjfr
Copy link
Member Author

This PR also happens to fix holoviz/panel#143.

I think we should merge this PR and then file an issue to discuss any suggestions related to letting users invalidate events.

@martindurant
Copy link

That's certainly fine with me.

@jlstevens
Copy link
Contributor

I think I'll go ahead and merge this PR so we can test it. I agree with Jim that the earlier discussion suggests that this is the right approach.

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.

4 participants