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
DynamicMap with streams force callback on first lookup after refresh #858
Changes from all commits
74d7dca
7da2ea8
1b37619
ea79755
742116f
1edb409
f323413
0fea997
bcdebc1
7bae403
e97a530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,3 +128,29 @@ def hierarchical(keys): | |
store1[v2].append(v1) | ||
hierarchies.append(store2 if hierarchy else {}) | ||
return hierarchies | ||
|
||
|
||
class dimensionless_cache(object): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the discussion about, I would call it
I don't think it needs an
Would be reasonable. The issue with using either For this reason, maybe something like this would be clearer:
Just some things to think about... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue is that making context manager conditional is awkward, which is why I moved the boolean onto the object. I agree with renaming the argument and making it optional though. |
||
Context manager which temporarily enables lookup of frame in the | ||
cache on a DynamicMap with dimensionless streams. Allows passing | ||
any Dimensioned object which might contain a DynamicMap and | ||
whether to enable the cache. This allows looking up an item | ||
without triggering the callback. Useful when the object is looked | ||
up multiple times as part of some processing pipeline. | ||
""" | ||
|
||
def __init__(self, obj, allow_cache_lookup=True): | ||
self.obj = obj | ||
self._allow_cache_lookup = allow_cache_lookup | ||
|
||
def __enter__(self): | ||
self.set_cache_flag(self._allow_cache_lookup) | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.set_cache_flag(False) | ||
|
||
def set_cache_flag(self, value): | ||
self.obj.traverse(lambda x: setattr(x, '_stream_cache_lookup', value), | ||
['DynamicMap']) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -787,7 +787,7 @@ def stream_parameters(streams, no_duplicates=True, exclude=['name']): | |
If no_duplicates is enabled, a KeyError will be raised if there are | ||
parameter name clashes across the streams. | ||
""" | ||
param_groups = [s.params().keys() for s in streams] | ||
param_groups = [s.contents.keys() for s in streams] | ||
names = [name for group in param_groups for name in group] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the fix! |
||
|
||
if no_duplicates: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From our discussion, we think it ought to be something like:
That way the variable isn't about streams and you can disable cache lookup on dynamic maps not matter how they are (or aren't) using streams.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we decided in the end that it is about streams.