Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

I think it was a mistake to use lock in cached_property at first place. In most 
cases there is nothing wrong in evaluating the cached value more than once. 
lru_cache() does not use a lock for calling the wrapped function, and it works 
well. The only lock in the Python implementation is for updating internal 
structure, it is released when the wrapped function is called. The C 
implementation uses the GIL for this purpose.

It is hard to get rid of the execution lock once it was introduced, but I think 
we should do it. Maybe deprecate cached_property and add a new decorator 
without a lock. Perhaps add separate decorators for automatically locking 
method execution, different decorators for different type of locking (global, 
per-method, per-instance, per-instance-and-method).

Java has the synchronized keyword which allows to add implicit lock to a 
method. As it turned out, it was a bad idea, and it is no longer used in the 
modern code.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43468>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to