The Stream.clear method now supports 'all', 'user' and 'internal' policies
@@ -150,11 +150,26 @@ class Stream(param.Parameterized):
return [s for p, s in sorted(self._subscribers)]
- def clear(self):
+ def clear(self, policy='all'):
"""
Clear all subscribers registered to this stream.
- """
- self._subscribers = []
+
+ The default policy of 'all' clears all subscribers. If policy is
+ set to 'user', only subscribers defined by the user are cleared
+ (precedence between zero and one). A policy of 'internal' clears
+ subscribers with precedence greater than unity used internally
+ by HoloViews.
+ """
+ policies = ['all', 'user', 'internal']
+ if policy not in policies:
+ raise ValueError('Policy for clearing subscribers must be one of %s' % policies)
+ if policy == 'all':
+ remaining = []
+ elif policy == 'user':
+ remaining = [s for (p,s) in self._subscribers if p <= 1]
+ else:
+ remaining = [s for (p,s) in self._subscribers if p > 1]
+ self._subscribers = remaining
def reset(self):
