On Wed, 29 Apr 2020 12:01:24 -0700
Raymond Hettinger <raymond.hettin...@gmail.com> wrote:
> 
> The call_once() decorator would need different logic:
> 
> 1) if the function has already been called and result is known, return the 
> prior result  :-)
> 2) if function has already been called, but the result is not yet known, 
> either block or fail  :-(

It definitely needs to block.

> 3) call the function, this cannot be reentrant :-(

Right.  The typical use for such a function is lazy initialization of
some resource, not recursive computation.

> 4) record the result for future calls.
> 
[...]
> 
> Would it fair to describe call_once() like this?
> 
> call_once() is just like lru_cache() but:
> 
> 1) guarantees that a function never gets called more than once
> 2) will block or fail if a thread-switch happens during a call

Definitely block.

> 3) only works for functions that take zero arguments
> 4) only works for functions that can never be reentrant
> 5) cannot make the one call guarantee across multiple processes
> 6) does not have instrumentation for number of hits
> 7) does not have a clearing or reset mechanism

Clearly, instrumentation and a clearing mechanism are not necessary.
They might be "nice to have", but needn't hinder initial adoption of
the API.

Regards

Antoine.

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NZ2VDB4WDPXP44NGZEXW2ACE424ODFBH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to