-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Params support for unwatching #4360
Comments
Hi there. Μe and my collaborator, would like to work with that issue. As novices to programming we are, we would appreciate any suggestions or guidelines conserning the building of the upper ability into Params, in order to have a more favorable start of our work. Thanks in advance |
I just made a subclass to work around this: class ParamStream(holoviews.streams.Params):
"""Extends :class:`holoviews.streams.Params` class.
Specifically provides the ability to unregister parameter watching
through the :meth:`unwatch` method.
"""
def __init__(self, parameterized=None, parameters=None, watch=True, watch_only=False, **params):
super().__init__(
parameterized = parameterized,
parameters = parameters,
watch = False,
watch_only = False,
**params
)
# Super class does not keep track of watchers, so we have to duplicate code
# here. See https://github.com/holoviz/holoviews/issues/4360.
self._watchers = [] # type: List[Watcher]
if watch:
# Subscribe to parameters
keyfn = lambda x: id(x.owner)
for _, group_iter in groupby(sorted(self.parameters, key=keyfn)):
group = list(group_iter)
watcher = group[0].owner.param.watch(self._watcher, [p.name for p in group])
self._watchers.append(watcher)
def unwatch(self):
"""Stop watching parameters."""
for watcher in self._watchers:
watcher.inst.param.unwatch(watcher)
self._watchers.clear() Feel free to copy. |
We'd very much appreciate a PR adding the
|
Thanks for contributing @alexbraditsas! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The
Params
stream class will watch the parameters by default:but it does not save the created
Watcher
objects returned by thewatch
method,so there is no easy way to unwatch them later. So if you are done with the stream but
not the underlying parameters the stream will be kept alive and will continue to get events.
You can work around this by constructing with
watch=False
and duplicatingthe code above, but it would be much nicer if this ability was built into
Params
itself.
The text was updated successfully, but these errors were encountered: