Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-07 Thread Brian Warner
Terry Jones wrote: > After I went to bed I realized that someone is immediately going to > want to have a cancel function that returns a deferred. And what > happens if something goes wrong in a cancel function? FWIW, the way I've dealt with these sorts of things (in Tahoe, at least) has been to

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-07 Thread Terry Jones
> "Glyph" == Glyph Lefkowitz writes: Glyph> This implies, to me, that the cancellation callback would be better Glyph> passed to addCallbacks(): effectively creating a third callback Glyph> chain going from invoker to responder rather than the other way Glyph> 'round as callbacks and errbacks

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-06 Thread Terry Jones
Hi Glyph It's very late here, so I'll limit myself to a few thousand lines of reply. > "Glyph" == Glyph Lefkowitz writes: Glyph> On Jan 6, 2010, at 7:09 AM, Terry Jones wrote: Glyph> What I mean is, there are a lot of weird little edge-cases in how Glyph> multiple layers of the stack intera

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-06 Thread Glyph Lefkowitz
On Jan 6, 2010, at 9:46 AM, sstein...@gmail.com wrote: > As far as I know, in my limited spelunking into Twisted's guts, Deferred's > pretty much only know about themselves and their callbacks so I'm not sure > whether there's a "ringmaster" that knows any more than that that could make > sure

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-06 Thread Glyph Lefkowitz
On Jan 6, 2010, at 7:09 AM, Terry Jones wrote: >> "Glyph" == Glyph Lefkowitz writes: > Glyph> On Jan 5, 2010, at 4:53 PM, Terry Jones wrote: > > Glyph> I understand what you're saying: you're interested in a subset of > Glyph> what I'm interested in, here. > > Yes. > Glyph> I think that c

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-06 Thread sstein...@gmail.com
On Jan 6, 2010, at 5:23 AM, Glyph Lefkowitz wrote: > I know what the use-cases are for stopping the underlying operation > (notifying the peer that you're not going to accept it, reclaiming the > resources); but if you're just going to let the operation complete eventually > anyway, why wouldn

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-06 Thread Terry Jones
> "Glyph" == Glyph Lefkowitz writes: Glyph> On Jan 5, 2010, at 4:53 PM, Terry Jones wrote: Glyph> I understand what you're saying: you're interested in a subset of Glyph> what I'm interested in, here. Yes. Glyph> The point I'm trying to make is that once you've gone to the trouble Glyph> of

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-06 Thread Glyph Lefkowitz
On Jan 5, 2010, at 4:53 PM, Terry Jones wrote: > I'm not sure if it's yet clear that I'm not trying *at all* to address > somehow stopping operations that are in progress. On the contrary, my code > always lets them run to their natural conclusion. It's just that if the > caller decides they're n

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Terry Jones
> "Glyph" == Glyph Lefkowitz writes: Glyph> And let's not forget, in long-running servers, it's possible to Glyph> "leak" operations, and the associated resources like file Glyph> descriptors. When the caller says that they're not interested in Glyph> the result of an operation any more, the

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Terry Jones
> "Tristan" == Tristan Seligmann writes: Tristan> On Tue, Jan 5, 2010 at 6:29 AM, Terry Jones wrote: >> - Once someone has made a function call, gotten a deferred, added >> ?call/errbacks to it, etc., it's gone. It's in flight. Forget about it. Tristan> The thing is, this attitude isn't alw

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Glyph Lefkowitz
On Jan 5, 2010, at 2:12 PM, Tristan Seligmann wrote: > On Tue, Jan 5, 2010 at 6:29 AM, Terry Jones wrote: >> - Once someone has made a function call, gotten a deferred, added >> call/errbacks to it, etc., it's gone. It's in flight. Forget about it. > > The thing is, this attitude isn't always

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Tristan Seligmann
On Tue, Jan 5, 2010 at 6:29 AM, Terry Jones wrote: > - Once someone has made a function call, gotten a deferred, added >  call/errbacks to it, etc., it's gone. It's in flight. Forget about it. The thing is, this attitude isn't always reasonable. Deferred is not necessarily the place to implement

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Terry Jones
Argh. sorry, there was a trivial cut & paste error in the code I just posted. The errback method should of course be: def errback(self, fail=None): if not self._called: self._called = True defer.Deferred.errback(self, fail) Terry _

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Terry Jones
Hi again Glyph, Andrew Below is a simpler and more flexible ControllableDeferred class. The idea is simple: you want a deferred that you can call/errback yourself, and which you can also deactivate so that it never fires. This is done by manipulating two normal deferreds (self, and a deferred re

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-05 Thread Terry Jones
> "Andrew" == Andrew Bennetts writes: Andrew> I think the key thing is to remember there are two distinct parts: Andrew> 1) an operation (which eventually will have a result or failure) Andrew> 2) a result Andrew> A Deferred takes care of managing 2. It's a placeholder for that Andrew>

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-04 Thread Andrew Bennetts
Terry Jones wrote: > I just wrote the below for fun. It's untested :-) > > It's a class that you initialize with a callable (f), and which gives you > back a deferred (d) that will fire when f fires. Alternately, you can fire > d yourself by calling 'callback' or 'errback' on the class instance a

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-04 Thread Terry Jones
As a final followup before bed... I chose not to have a 'cancel' method on my class because that seemed misleading. You're not really canceling anything. You're just asking that a deferred that you got earlier be fired right now with a value of your choosing. So I made 2 methods, and named them 'c

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-04 Thread Terry Jones
Hi Glyph I read through without trying to get all the details (some are not relevant to me, see below). I'll make a few comments here, then continue in the ticket, supposing there's interest. - It would simplify things to separate discussion of cancelin

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-04 Thread Terry Jones
> "Glyph" == Glyph Lefkowitz writes: Glyph> I already lost you at the first sentence. :-) Sorry. Glyph> The class below never appears to use 'self._f' Oops, that should have been a self._f in the call method. Glyph> and ... Deferreds are things that fire, I don't see how the callable Glyp

Re: [Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-04 Thread Glyph Lefkowitz
On Jan 4, 2010, at 9:22 PM, Terry Jones wrote: > I just wrote the below for fun. It's untested :-) > It's a class that you initialize with a callable (f), and which gives you > back a deferred (d) that will fire when f fires. Alternately, you can fire > d yourself by calling 'callback' or 'errb

[Twisted-Python] A pseudo-deferred class that can be canceled

2010-01-04 Thread Terry Jones
I just wrote the below for fun. It's untested :-) It's a class that you initialize with a callable (f), and which gives you back a deferred (d) that will fire when f fires. Alternately, you can fire d yourself by calling 'callback' or 'errback' on the class instance and passing a value. That val