[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread Paul Ganssle
On 4/30/20 4:47 PM, raymond.hettin...@gmail.com wrote: > Would either of the existing solutions work for you? > > class X: > def __init__(self, name): > self.name = name > > @cached_property > def title(self): > print("compute title once") > return self.name.title()

[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread Carl Meyer
On Thu, Apr 30, 2020 at 3:12 PM Raymond Hettinger wrote: > Thanks for the concrete example. AFAICT, it doesn't require (and probably > shouldn't have) a lock to be held for the duration of the call. Would it be > fair to say the 100% of your needs would be met if we just added this to the > f

[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread Raymond Hettinger
> On Apr 30, 2020, at 10:44 AM, Carl Meyer wrote: > > On Wed, Apr 29, 2020 at 9:36 PM Raymond Hettinger > wrote: >> Do you have some concrete examples we could look at? I'm having trouble >> visualizing any real use cases and none have been presented so far. > > This pattern occurs not in

[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread raymond . hettinger
Would either of the existing solutions work for you? class X: def __init__(self, name): self.name = name @cached_property def title(self): print("compute title once") return self.name.title() @property @lru_cache def upper(self): print("compute u

[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread Raymond Hettinger
> On Apr 30, 2020, at 6:32 AM, Joao S. O. Bueno wrote: > > Of course this is meant to be something simple - so there are no "real > world use cases" that are "wow, it could not have > been done without it". The proposed implementation does something risky, it hold holds a non-reentrant lock a

[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread Carl Meyer
On Wed, Apr 29, 2020 at 9:36 PM Raymond Hettinger wrote: > Do you have some concrete examples we could look at? I'm having trouble > visualizing any real use cases and none have been presented so far. This pattern occurs not infrequently in our Django server codebase at Instagram. A typical ca

[Python-Dev] Re: Virtual machine bleeds into generator implementation?

2020-04-30 Thread Skip Montanaro
> > Thanks for the replies. I will cook up some private API in my cpython > fork. Whether or not my new vm ever sees the light of day, I think it > would be worthwhile to consider a proper API (even a _PyEval macro or > two) for the little dance the two subsystems do. > I committed a change to my

[Python-Dev] Re: Adding a "call_once" decorator to functools

2020-04-30 Thread Joao S. O. Bueno
On Thu, 30 Apr 2020 at 00:37, Raymond Hettinger wrote: > > > > > On Apr 29, 2020, at 4:20 PM, Antoine Pitrou wrote: > > > > On Wed, 29 Apr 2020 12:01:24 -0700 > > Raymond Hettinger wrote: > >> > Also, if you know of a real world use case, what solution is currently being > used. I'm not sure w