[Twisted-web] streaming request (was: status of Twisted Web and Web 2)

Jean-Paul Calderone exarkun at divmod.com
Thu Mar 6 10:28:26 EST 2008


On Thu, 6 Mar 2008 08:13:56 -0700, Andrew McNabb <amcnabb at mcnabbs.org> wrote:
>On Thu, Mar 06, 2008 at 09:51:00AM -0500, Jean-Paul Calderone wrote:
>>>
>>> Actually, after looking at my code again, it turns out that what I am
>>> doing is actually a mix of attempt 2 and attempt 3.  This is the code
>>> that copies the deferred:
>>>
>>>    newdef = defer.Deferred()
>>>    newdef.callbacks = list(self.deferred.callbacks)
>>>    newdef.callback(False)
>>>
>>
>> *cries*
>>
>> You're not supposed to read or write the `callbacks´ attribute like that.
>
>I told you I thought that was ugly.  Do you have a better way to do
>this? :)

Not directly.  I'd probably try turning the code inside-out side that
code which wants a group of callbacks to be used for more than one event
has an opportunity to get more than one "fresh" Deferred from the event
source and can add the callbacks to as many of them as it likes.  Hopefully
this will all be mooted by the other potential solution.

>
>>> That makes sense, but in the streaming case I really think that you
>>> need to call back every time data comes in.
>>
>> Yes, definitely.  `IStreamingRequestHandler´ would have some method like
>> `someMoreRequestDataReceived´ and it would be called as many times as
>> necessary for a single request until the entire request body has been
>> delivered.
>
>You still want callbacks.  You might have other places that need
>notification of the event.  We don't want to call a method over and
>over.  We want to _callback_ over and over.
>

This... I don't understand.  A callback is just an object which is callable,
often with some arguments.  I would generally use the word "callback" to
describe what `someMoreRequestDataReceived´ is.  Why do you think it doesn't
qualify, and what do you mean when you say "callback"?

Jean-Paul



More information about the Twisted-web mailing list