~djfroofy/+junk/trialtimeouts-2675

« back to all changes in this revision

Viewing changes to doc/web/howto/web-in-60/wsgi.xhtml

  • Committer: exarkun
  • Date: 2010-09-18 15:36:46 UTC
  • Revision ID: svn-v4:bbbe8e31-12d6-0310-92fd-ac37d47ddeeb:trunk:30040
Merge sphinx-web60-4577

Author: jdb
Reviewer: exarkun
Fixes: #4577

Tweaks to the Lore markup in the Web documentation to make it
more amenable to conversion to Sphinx.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
<body>
11
11
<h1>WSGI</h1>
12
12
 
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>
18
19
 
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)
54
55
</pre>
55
56
 
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
65
 
reactor to it.</p>
 
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>
66
68
 
67
69
<p>The second parameter passed to <code>WSGIResource</code> is
68
70
a <code class="API"