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

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Jan 5 15:27:16 EST 2010

On Jan 5, 2010, at 2:12 PM, Tristan Seligmann wrote:

> On Tue, Jan 5, 2010 at 6:29 AM, Terry Jones <terry at jon.es> 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 cancellation, but I think the idiom
> itself is important. Certainly there are some operations where
> cancellation is not feasible; perhaps because the underlying APIs do
> not support cancellation, or because allowing the operation to
> complete is quicker/easier than trying to interrupt it. But, consider
> something like the transfer of a 512 TB file; cancellation /is/
> possible, through closing the TCP connection, and the operation is
> significantly expensive, so "just forget it and let it finish" is a
> somewhat cavalier attitude to take.

And let's not forget, in long-running servers, it's possible to "leak" operations, and the associated resources like file descriptors.  When the caller says that they're not interested in the result of an operation any more, the library should clean up as much as possible, otherwise you'll start running out of those resources eventually.

More information about the Twisted-Python mailing list