-
Notifications
You must be signed in to change notification settings - Fork 145
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
Create thread-safe @cached_property #81
Comments
Good idea, @pared. I thought about this myself too ;) |
Apologies for asking a question on a resolved issue, but I didn't want to open a new one. Question: given that a Thanks for this great library. |
You should really create new issues for things like this, it might be simply lost here) Python 3.8 @wrap_prop(threading.RLock())
@cached_property
def prop_name(self):
# ...
return value Which will make us use 2 rlocks if Python 3.8 If I decide to move to Python 3.8 way I will need to use its implementation for older pythons too, otherwise it will be incosistent regarding thread-safety. Then to follow that logic I will need to make thread-safe other caching parts of funcy: So, it looks like a shift, which needs some thinking. I'll take my time. |
Currently, it is possible that
cached_property
will create multiple objects when used in multi-threaded context.For example:
Will most likely create new
client
properties for each thread, however, if we comment outsleep
there is a chance that it will be a single object.
It would be nice to make
@cached_property
thread-safe or create a new decorator that could do that.The text was updated successfully, but these errors were encountered: