[Twisted-web] [nevow & deferreds] page rendering occurs before data is available after callback

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Wed Dec 2 12:45:36 EST 2009


On 05:01 pm, matthieu.huin at wallix.com wrote:
>Greetings,
>
>I need to render a page with Nevow containing data extracted from a
>database. The query might take time so it is taken care of with
>twisted.adbapi, and thus with a Deferred.
>
>My render function returns this Deferred - to which some callbacks have
>been added to format the data. All is well as long as the request is
>fast enough for the Deferred to be dealt with quasi-synchronously. If
>the query takes too much time, the render function simply returns the
>Deferred, which is set at None, instead of its result value.

It's hard to tell from the code that you've posted, but it sounds like 
your "too much time" case is probably triggering a different path 
through your code - one that results in one of the necessary Deferreds 
not being chained to the Deferred returned from your renderHTTP 
implementation.  This results in the renderHTTP Deferred firing while 
some other asynchronous task is still going on.

Are you aware of nevow.guard, which implements authentication in a 
general way and can be applied to arbitrary other pages?  That might let 
you delete a lot of your code, possibly getting rid of the bug in the 
process, but at least reducing the amount of code you need to look 
through to find the problem.

Jean-Paul



More information about the Twisted-web mailing list