13
<p>The goal of this example is to show you how to use <code class="API"
14
base="twisted.web.wsgi">WSGIResource</code>, another existing
15
<code class="API" base="twisted.web.resource">Resource</code> subclass, to serve
16
<a href="http://www.python.org/dev/peps/pep-0333/">WSGI applications</a> in a
17
Twisted Web server.</p>
13
<p>The goal of this example is to show you how to
14
use <code class="API" base="twisted.web.wsgi">WSGIResource</code>,
15
another existing <code class="API"
16
base="twisted.web.resource">Resource</code> subclass, to
17
serve <a href="http://www.python.org/dev/peps/pep-0333/">WSGI applications</a>
18
in a Twisted Web server.</p>
19
20
<p>Note thate <code>WSGIResource</code> is a multithreaded WSGI container. Like
20
21
any other WSGI container, you can't do anything asynchronous in your WSGI
53
54
resource = WSGIResource(reactor, reactor.getThreadPool(), application)
56
<p>Let's dwell on this line for a minute. The first parameter passed to
57
<code>WSGIResource</code> is the reactor. Despite the fact that the reactor is
58
global and any code that wants it can always just import it (as, in fact, this
59
rpy script simply does itself), passing it around as a parameter leaves the door
60
open for certain future possibilities - for example, having more than one
61
reactor. There are also testing implications. Consider how much easier it is to
62
unit test a function that accepts a reactor - perhaps a mock reactor specially
63
constructed to make your tests easy to write - rather than importing the real
64
global reactor. That's why <code>WSGIResource</code> requires you to pass the
57
<p>Let's dwell on this line for a minute. The first parameter passed
58
to <code>WSGIResource</code> is the reactor. Despite the fact that the
59
reactor is global and any code that wants it can always just import it
60
(as, in fact, this rpy script simply does itself), passing it around
61
as a parameter leaves the door open for certain future possibilities -
62
for example, having more than one reactor. There are also testing
63
implications. Consider how much easier it is to unit test a function
64
that accepts a reactor - perhaps a mock reactor specially constructed
65
to make your tests easy to write - rather than importing the real
66
global reactor. That's why <code>WSGIResource</code> requires you to
67
pass the reactor to it.</p>
67
69
<p>The second parameter passed to <code>WSGIResource</code> is
68
70
a <code class="API"