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 something.
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 application. 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 thread. 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 suggested correctly. 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 -- Jim Fulton mailto:[EMAIL PROTECTED] Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org _______________________________________________ Web-SIG mailing list [email protected] Web SIG: http://www.python.org/sigs/web-sig Unsubscribe: http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com
