Server/gateway 接受HTTP请求和提供并发。每当接收HTTP请求,就会调用callable object:
1.接收HTTP请求,不关心HTTP method,url等
2.为environ提供必要的参数
3.实现回调函数start_response,并传递给callable object
4.多线程调用callable object
# application/framework side
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['This is a python application!']
# server/gateway side
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('0.0.0.0', 8080, application)
server.serve_forever()
参考:
https://www.cnblogs.com/-wenli/p/10884168.html