Re: [Twisted-Python] Waiting for a contended resource

2018-03-12 Thread Richard van der Hoff
Thank you for all for all the answers so far, particularly to Ilya and Jean-Paul who provided some very helpful code samples. It's interesting to realise that, by avoiding locking, we can end up with a much more efficient implementation. I'll have to figure out how widely we can apply this

Re: [Twisted-Python] Waiting for a contended resource

2018-03-12 Thread Ilya Skriblovsky
Thanks for correction, Jean-Paul, you're absolutly right пн, 12 мар. 2018 г. в 23:00, Jean-Paul Calderone : > On Mon, Mar 12, 2018 at 3:52 PM, Ilya Skriblovsky < > ilyaskriblov...@gmail.com> wrote: > >> Hi, Richard, >> >> I've used class like this to cache the result

Re: [Twisted-Python] Waiting for a contended resource

2018-03-12 Thread Jean-Paul Calderone
On Mon, Mar 12, 2018 at 3:52 PM, Ilya Skriblovsky wrote: > Hi, Richard, > > I've used class like this to cache the result of Expensive Calculation: > > class DeferredCache: > pending = None > result = None > failure = None > > def __init__(self,

Re: [Twisted-Python] Waiting for a contended resource

2018-03-12 Thread Ilya Skriblovsky
Hi, Richard, I've used class like this to cache the result of Expensive Calculation: class DeferredCache: pending = None result = None failure = None def __init__(self, expensive_func): self.expensive_func = expensive_func def __call__(self): if self.pending

Re: [Twisted-Python] Waiting for a contended resource

2018-03-12 Thread L. Daniel Burr
Hi Richard, On March 12, 2018 at 1:49:41 PM, Richard van der Hoff (rich...@matrix.org) wrote: Hi folks, I thought I'd poll the list on the best way to approach a problem in  Twisted. The background is that we have a number of resources which can be  requested by a REST client, and which are

[Twisted-Python] Waiting for a contended resource

2018-03-12 Thread Richard van der Hoff
Hi folks, I thought I'd poll the list on the best way to approach a problem in Twisted. The background is that we have a number of resources which can be requested by a REST client, and which are calculated on demand. The calculation is moderately expensive (can take multiple seconds), so