[Web-SIG] When must applications call the WSGI start_response callable.
jim at zope.com
Thu Dec 15 21:01:44 CET 2005
I'm a bit unclear about the timing of the start_response call.
I think this is because the PEP is unclear, but perhaps I missed
It doesn't appear that the PEP says when the start_response callable
must be called. It gives several examples. In most, the callback is
called when the application is called, but in one example, the
callback is called in the __iter__ of the result of calling the
Here's what I think the PEP should say (something like):
"The start_response callback must be:
- called when the application is called,
- called when the result iterator is computed, or
- it must be called asynchronously, typically from an application
Normally an application will call the start_response callable when the
application is called or when the result iterator is constructed, as
shown in the first 2 examples. An application, or more commonly, a
middleware component that provides it's own thread management might
delay starting the response. A server should not begin iterating
over the result until the start_response callable has been called."
Why do I want this? It appears that this would be needed to enable
middleware components that manage application threads. I can imagine
though that there aren't any existing servers that handle what I've
I do think it would be straightforward for servers to handle this
correctly, especially for asynchronous servers like Twisted
and ayncore-based servers. Perhaps this could be an optional feature
of the servers. Servers supporting this feature would be prepared to
delay response output until start_response is called. Servers unable
to do this would generate errors if start_response hasn't been called
by the time the result iterator has been constructed.
In any case, I think the PEP needs to specify more clearly when
start_response can be called.
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Web-SIG