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

Andrew McNabb amcnabb at mcnabbs.org
Wed Mar 5 22:09:52 EST 2008


On Wed, Mar 05, 2008 at 09:13:44PM -0500, Jean-Paul Calderone wrote:
> On Wed, 5 Mar 2008 18:52:50 -0700, Andrew McNabb <amcnabb at mcnabbs.org> wrote:
>>
>> I've written some code that uses Twisted Web, and it seemed a little
>> basic.  For example, I had to make some modifications in order to
>> receive large files in progress instead of waiting until they were done
>> downloading.
>
> Does this code have tests?  Is it compatible with "normal" twisted.web
> usage?  Can I have the code?

My answer to all three questions is "sort of."  If you (or others) could
help me resolve a problem I ran into, I could change all of those to a
"yes."

The problem that I ran into is that with streaming requests, I would
like to be able to call back multiple times.  It makes sense that a
normal deferred can only be called back once.  I couldn't find anything
in Twisted that you might call a "multi-deferred" (to make it simple to
callback multiple times).  It's been a while, so let me see if I
remember what I tried.

My first attempt was to callback with a new deferred as the callback
value.  Then the callback function could add itself to the new deferred
and get called again the next time data arrive.  I thought this was a
clean approach, but it turns out that if you try to call back with a new
deferred, there's a TypeError.  I couldn't figure out why it didn't like
this.

My second attempt was to create a new deferred each time data arrived
and to copy the callback list from the previous deferred.  This worked,
but it felt dirty, so I got rid of it.

My third and final attempt was to tie the downloader in to my
application.  Every time data arrive, the downloader sends it to the
object that needs it.  This isn't a very general solution, but it is
very short and readable.

Anyway, if you know of a better way to deal with this issue, I would be
happy to modify my code for it.  If you're happy with what I've got, I
would be happy to email it to you, but I wouldn't recommend adding it to
Twisted Web until it's more general.

Thanks.


-- 
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20080305/3fa7adba/attachment.pgp


More information about the Twisted-web mailing list