48
<p>Before defining the render method, we're going to define an errback (an
49
errback being a callback that gets called when there's an error), though. This
50
will be the errback attached to the <code>Deferred</code> returned by
51
<code>Request.notifyFinish</code>. It will cancel the delayed call to
52
<code>_delayedRender</code>.</p>
48
<p>Before defining the render method, we're going to define an errback
49
(an errback being a callback that gets called when there's an error),
50
though. This will be the errback attached to the <code>Deferred</code>
51
returned by <code>Request.notifyFinish</code>. It will cancel the
52
delayed call to <code>_delayedRender</code>.</p>
54
54
<pre class="python">
55
55
def _responseFailed(self, err, call):
59
<p>Finally, the render method will set up the delayed call just as it did
60
before, and return <code>NOT_DONE_YET</code> likewise. However, it will also use
61
<code>Request.notifyFinish</code> to make sure <code>_responseFailed</code> is
62
called if appropriate.</p>
59
<p>Finally, the render method will set up the delayed call just as it
60
did before, and return <code>NOT_DONE_YET</code> likewise. However, it
61
will also use <code>Request.notifyFinish</code> to make
62
sure <code>_responseFailed</code> is called if appropriate.</p>
64
64
<pre class="python">
65
65
def render_GET(self, request):
68
68
return NOT_DONE_YET
71
<p>Notice that since <code>_responseFailed</code> needs a reference to the
72
delayed call object in order to cancel it, we passed that object to
73
<code>addErrback</code>. Any additional arguments passed to
74
<code>addErrback</code> (or <code>addCallback</code>) will be passed along to
75
the errback after the <code class="API"
76
base="twisted.python.failure">Failure</code> instance which is always passed as
77
the first argument. Passing <code>call</code> here means it will be passed to
78
<code>_responseFailed</code>, where it is expected and required.</p>
71
<p>Notice that since <code>_responseFailed</code> needs a reference to
72
the delayed call object in order to cancel it, we passed that object
73
to <code>addErrback</code>. Any additional arguments passed
74
to <code>addErrback</code> (or <code>addCallback</code>) will be
75
passed along to the errback after the <code class="API"
76
base="twisted.python.failure">Failure</code> instance which is always
77
passed as the first argument. Passing <code>call</code> here means it
78
will be passed to <code>_responseFailed</code>, where it is expected
80
81
<p>That covers almost all the code for this example. Here's the entire example
81
82
without interruptions, as an <a href="rpy-scripts.xhtml">rpy script</a>:</p>