[Twisted-Python] Re: Resource.render() returning NOT_DONE_YET

Bob Ippolito bob at redivi.com
Mon Apr 28 11:11:33 MDT 2003


On Monday, Apr 28, 2003, at 12:17 America/New_York, Clark C. Evans 
wrote:

> On Mon, Apr 28, 2003 at 04:09:35PM +0000, Clark C. Evans wrote:
> | I was just giving a quick Twisted tutorial to someone using
> | twisted and as we were breaking page construction into more
> | than one chunk... an unexpected stumbling block occurred --
> | returning NOT_DONE_YET form the resource's render() function.
> |
> | I was thinking about two other options:
> |
> |   1.  Perhaps NOT_DONE_YET could just be None, this
> |       way, it can be the default return value.  As I'm
> |       browsing through my code this is the most common
> |       return... why not make it the default.
>
>         Err, this isn't exactly what I was thinking.  What
>         I was proposing...  if during the scope of the render()
>         function, req.write() is called, then a None value
>         would be an allowable return.   And if None is returned,
>         req.finish() would be called automagically.
>
> |   2.  Alternatively, allow a Deferred to be a return
> |       value.  Then the underlying caller can add
> |       result.finish() to the deferred chain.   This
> |       has the advantage of not requiring finish() to
> |       really be managed.   Either the return value is
> |       a string, a Deferred, (or for backwards compatibiliy
> |       NOT_DONE_YET).  In either of the primary cases,
> |       result.finish() always gets called... thus making
> |       it easier on newbies.
> |
> | Ideally, both of the above options could be used...

Or, you could just deprecate NOT_DONE_YET and say "if you're doing 
something that uses req.write you need to return a deferred".

For case 1, you return a deferred with an empty rval (None or '').  
This signifies that you took care of req.write.
For case 2, you return a deferred with the page as the rval.  This 
signifies that you want the server to req.write.

I think that's the simplest way, and takes the return values for render 
down to three, but really two for new code:
1) a string
2) a deferred
3) a deprecated NOT_DONE_YET





More information about the Twisted-Python mailing list