-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add maybe_open_context()
an actor wide task-resource cache
#257
Conversation
tractor/trionics/_mngrs.py
Outdated
# Further potential examples of interest: | ||
# https://gist.github.com/njsmith/cf6fc0a97f53865f2c671659c88c1798#file-cache-py-L8 | ||
|
||
class cache: |
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.
It's unusual to have a lower-case class name, IMO.
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.
indeed. do you think Cache
is ok even though it's never being used as an instance?
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.
Yeah, it's totally ok.
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.
we might want to make it _Cache
to keep it internal?
8c6e4ee
to
35ac323
Compare
ef5162a
to
52fef7f
Compare
0bd1be5
to
903ca53
Compare
903ca53
to
c747293
Compare
@overclockworked64 there I think the test should explain a little better how this works. I also fixed up the naming concern to |
c8ad5d2
to
5623daf
Compare
gahhhhh windowwwwws |
Lol this
|
If the streaming improvements here seem too lumped in we can also break them out into a separate PR. It might be better to more formally document those fixes and the new test? |
83d395c
to
a95e04c
Compare
After more extensive testing I realized that keying on the context manager *instance id* isn't going to work since each entering task is going to create a unique key XD Instead pass the manager function as `acm_func` and optionally allow keying the resource on the passed `kwargs` (if hashable) or the `key:str`. Further, pass the key to the enterer task and avoid a separate keying scheme for the manager versus the value it delivers. Don't bother with checking and releasing the lock in `finally:` block, it should be an error if it's still locked.
a95e04c
to
953d15b
Compare
Like it sounds: a context manager that only opens a new actor-global (aka mem local) resource if one isn't already cached.
This is particularly handy for resources that can be shared by multiple tasks in and actor where the user desires that the lifetime of the resource is maintained until the final user task completes.
Still needs tests obviously.
UPDATE:
This ended up turning into a foray into fixing
MsgStream
closure/termination semantics after trying to get the original resource caching test working.Todo tests:
trio
tasks get the same cached value