{"id":29099,"date":"2025-04-20T05:41:14","date_gmt":"2025-04-19T21:41:14","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/29099.html"},"modified":"2025-04-20T05:41:14","modified_gmt":"2025-04-19T21:41:14","slug":"%e4%bb%80%e4%b9%88%e6%98%afasgi%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/29099.html","title":{"rendered":"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668"},"content":{"rendered":"<h4>\u5f15\u8a00&#xff1a;\u4eceWSGI\u5230ASGI<\/h4>\n<p>\u5728\u63a2\u8ba8ASGI\u670d\u52a1\u5668\u4e4b\u524d&#xff0c;\u6211\u4eec\u9996\u5148\u9700\u8981\u4e86\u89e3\u5176\u524d\u8eab\u2014\u2014WSGI&#xff08;Web Server Gateway Interface&#xff09;\u3002WSGI\u662fPython\u4e2d\u7528\u4e8eWeb\u670d\u52a1\u5668\u4e0eWeb\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u901a\u4fe1\u7684\u6807\u51c6\u63a5\u53e3\u3002\u5b83\u5b9a\u4e49\u4e86\u670d\u52a1\u5668\u5982\u4f55\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u4ee5\u53ca\u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u54cd\u5e94\u8bf7\u6c42\u3002\u7136\u800c&#xff0c;\u968f\u7740Web\u6280\u672f\u7684\u53d1\u5c55&#xff0c;\u5c24\u5176\u662fWebSockets\u548cHTTP\/2\u7b49\u65b0\u534f\u8bae\u7684\u51fa\u73b0&#xff0c;WSGI\u7684\u5c40\u9650\u6027\u9010\u6e10\u663e\u73b0\u3002\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u4e9b\u65b0\u9700\u6c42&#xff0c;ASGI&#xff08;Asynchronous Server Gateway Interface&#xff09;\u5e94\u8fd0\u800c\u751f\u3002<\/p>\n<h4>\u4ec0\u4e48\u662fASGI&#xff1f;<\/h4>\n<p>ASGI\u662fWSGI\u7684\u7ee7\u4efb\u8005&#xff0c;\u65e8\u5728\u63d0\u4f9b\u4e00\u4e2a\u5f02\u6b65\u7684\u3001\u652f\u6301\u591a\u79cd\u534f\u8bae\u7684\u63a5\u53e3\u3002\u4e0eWSGI\u4e0d\u540c&#xff0c;ASGI\u4e0d\u4ec5\u652f\u6301\u4f20\u7edf\u7684HTTP\u8bf7\u6c42&#xff0c;\u8fd8\u652f\u6301WebSocket\u3001HTTP\/2\u4ee5\u53ca\u672a\u6765\u7684\u534f\u8bae\u3002ASGI\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u8ba9Python Web\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u5904\u7406\u5f02\u6b65\u8bf7\u6c42&#xff0c;\u4ece\u800c\u63d0\u5347\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002<\/p>\n<h5>ASGI\u7684\u6838\u5fc3\u6982\u5ff5<\/h5>\n<li>\u5f02\u6b65\u652f\u6301&#xff1a;ASGI\u5e94\u7528\u7a0b\u5e8f\u662f\u5f02\u6b65\u7684&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u53ef\u4ee5\u5728\u7b49\u5f85I\/O\u64cd\u4f5c&#xff08;\u5982\u6570\u636e\u5e93\u67e5\u8be2\u6216\u7f51\u7edc\u8bf7\u6c42&#xff09;\u65f6\u91ca\u653eCPU\u8d44\u6e90&#xff0c;\u4ece\u800c\u63d0\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3002<\/li>\n<li>\u534f\u8bae\u591a\u6837\u6027&#xff1a;ASGI\u4e0d\u4ec5\u652f\u6301HTTP&#xff0c;\u8fd8\u652f\u6301WebSocket\u3001HTTP\/2\u7b49\u534f\u8bae&#xff0c;\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u7075\u6d3b\u5e94\u5bf9\u4e0d\u540c\u7684\u901a\u4fe1\u9700\u6c42\u3002<\/li>\n<li>\u4e8b\u4ef6\u9a71\u52a8&#xff1a;ASGI\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7\u4e8b\u4ef6\u9a71\u52a8\u7684\u65b9\u5f0f\u5904\u7406\u8bf7\u6c42&#xff0c;\u8fd9\u4f7f\u5f97\u5b83\u4eec\u80fd\u591f\u9ad8\u6548\u5730\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u3002<\/li>\n<h4>ASGI\u4e0eWSGI\u7684\u533a\u522b<\/h4>\n<p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3ASGI&#xff0c;\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5b83\u4e0eWSGI\u7684\u4e3b\u8981\u533a\u522b&#xff1a;<\/p>\n<ul>\n<li>\u540c\u6b65 vs \u5f02\u6b65&#xff1a;WSGI\u662f\u540c\u6b65\u7684&#xff0c;\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u4f1a\u963b\u585e\u670d\u52a1\u5668\u76f4\u5230\u5904\u7406\u5b8c\u6210\u3002\u800cASGI\u662f\u5f02\u6b65\u7684&#xff0c;\u5141\u8bb8\u670d\u52a1\u5668\u5728\u7b49\u5f85I\/O\u64cd\u4f5c\u65f6\u5904\u7406\u5176\u4ed6\u8bf7\u6c42\u3002<\/li>\n<li>\u534f\u8bae\u652f\u6301&#xff1a;WSGI\u4ec5\u652f\u6301HTTP\u534f\u8bae&#xff0c;\u800cASGI\u652f\u6301\u591a\u79cd\u534f\u8bae&#xff0c;\u5305\u62ecWebSocket\u548cHTTP\/2\u3002<\/li>\n<li>\u5e76\u53d1\u5904\u7406&#xff1a;\u7531\u4e8e\u5f02\u6b65\u7279\u6027&#xff0c;ASGI\u5728\u5904\u7406\u9ad8\u5e76\u53d1\u8bf7\u6c42\u65f6\u8868\u73b0\u66f4\u4f73\u3002<\/li>\n<\/ul>\n<h4>ASGI\u7684\u5de5\u4f5c\u539f\u7406<\/h4>\n<p>ASGI\u7684\u5de5\u4f5c\u539f\u7406\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u63a5\u6536\u8bf7\u6c42&#xff1a;ASGI\u670d\u52a1\u5668\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42&#xff0c;\u5e76\u5c06\u5176\u4f20\u9012\u7ed9ASGI\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li>\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f&#xff1a;ASGI\u670d\u52a1\u5668\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u7684__call__\u65b9\u6cd5&#xff0c;\u5e76\u5c06\u8bf7\u6c42\u4fe1\u606f\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u3002<\/li>\n<li>\u5904\u7406\u8bf7\u6c42&#xff1a;\u5e94\u7528\u7a0b\u5e8f\u5904\u7406\u8bf7\u6c42&#xff0c;\u5e76\u8fd4\u56de\u54cd\u5e94\u3002\u7531\u4e8e\u662f\u5f02\u6b65\u7684&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u7b49\u5f85I\/O\u64cd\u4f5c\u65f6\u91ca\u653eCPU\u8d44\u6e90\u3002<\/li>\n<li>\u53d1\u9001\u54cd\u5e94&#xff1a;ASGI\u670d\u52a1\u5668\u5c06\u5e94\u7528\u7a0b\u5e8f\u8fd4\u56de\u7684\u54cd\u5e94\u53d1\u9001\u56de\u5ba2\u6237\u7aef\u3002<\/li>\n<h4>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u4e00\u4e2a\u7b80\u5355\u7684ASGI\u5e94\u7528\u7a0b\u5e8f<\/h4>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684ASGI\u5e94\u7528\u7a0b\u5e8f\u793a\u4f8b&#xff0c;\u4f7f\u7528\u4e86uvicorn\u4f5c\u4e3aASGI\u670d\u52a1\u5668\u3002<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">app<\/span><span class=\"token punctuation\">(<\/span>scope<span class=\"token punctuation\">,<\/span> receive<span class=\"token punctuation\">,<\/span> send<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> scope<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;http&#039;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">await<\/span> send<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;http.response.start&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#039;status&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#039;headers&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n                <span class=\"token punctuation\">[<\/span><span class=\"token string\">b&#039;content-type&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">b&#039;text\/plain&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">await<\/span> send<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;http.response.body&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#039;body&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">b&#039;Hello, ASGI!&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h5>\u4ee3\u7801\u89e3\u91ca<\/h5>\n<ul>\n<li>scope&#xff1a;\u5305\u542b\u4e86\u8bf7\u6c42\u7684\u6240\u6709\u4fe1\u606f&#xff0c;\u5982\u8bf7\u6c42\u7c7b\u578b&#xff08;HTTP\u3001WebSocket\u7b49&#xff09;\u3001\u8bf7\u6c42\u8def\u5f84\u3001\u8bf7\u6c42\u5934\u7b49\u3002<\/li>\n<li>receive&#xff1a;\u4e00\u4e2a\u5f02\u6b65\u51fd\u6570&#xff0c;\u7528\u4e8e\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u6d88\u606f\u3002<\/li>\n<li>send&#xff1a;\u4e00\u4e2a\u5f02\u6b65\u51fd\u6570&#xff0c;\u7528\u4e8e\u53d1\u9001\u6d88\u606f\u7ed9\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d&#xff0c;\u6211\u4eec\u68c0\u67e5scope[&#039;type&#039;]\u662f\u5426\u4e3a&#039;http&#039;&#xff0c;\u5982\u679c\u662f&#xff0c;\u5219\u53d1\u9001\u4e00\u4e2aHTTP\u54cd\u5e94\u3002\u54cd\u5e94\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206&#xff1a;http.response.start\u548chttp.response.body\u3002\u524d\u8005\u5b9a\u4e49\u4e86\u54cd\u5e94\u7684\u72b6\u6001\u7801\u548c\u5934\u90e8\u4fe1\u606f&#xff0c;\u540e\u8005\u5305\u542b\u4e86\u54cd\u5e94\u7684\u4e3b\u4f53\u5185\u5bb9\u3002<\/p>\n<h4>\u5b9e\u9645\u5e94\u7528&#xff1a;\u4f7f\u7528ASGI\u6784\u5efaWebSocket\u5e94\u7528<\/h4>\n<p>ASGI\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5b83\u4e0d\u4ec5\u652f\u6301HTTP&#xff0c;\u8fd8\u652f\u6301WebSocket\u7b49\u534f\u8bae\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684WebSocket\u5e94\u7528\u793a\u4f8b&#xff1a;<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">websocket_app<\/span><span class=\"token punctuation\">(<\/span>scope<span class=\"token punctuation\">,<\/span> receive<span class=\"token punctuation\">,<\/span> send<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> scope<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;websocket&#039;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">while<\/span> <span class=\"token boolean\">True<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            message <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> receive<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> message<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;websocket.connect&#039;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">await<\/span> send<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;websocket.accept&#039;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">elif<\/span> message<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;websocket.receive&#039;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">await<\/span> send<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;websocket.send&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                    <span class=\"token string\">&#039;text&#039;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;You said: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>message<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;text&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">elif<\/span> message<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;type&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#039;websocket.disconnect&#039;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">break<\/span><\/p>\n<h5>\u4ee3\u7801\u89e3\u91ca<\/h5>\n<ul>\n<li>websocket.connect&#xff1a;\u5f53WebSocket\u8fde\u63a5\u5efa\u7acb\u65f6\u89e6\u53d1\u3002<\/li>\n<li>websocket.receive&#xff1a;\u5f53\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u65f6\u89e6\u53d1\u3002<\/li>\n<li>websocket.send&#xff1a;\u7528\u4e8e\u53d1\u9001\u6d88\u606f\u7ed9\u5ba2\u6237\u7aef\u3002<\/li>\n<li>websocket.disconnect&#xff1a;\u5f53WebSocket\u8fde\u63a5\u65ad\u5f00\u65f6\u89e6\u53d1\u3002<\/li>\n<\/ul>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d&#xff0c;\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684WebSocket\u5e94\u7528&#xff0c;\u5b83\u63a5\u6536\u5ba2\u6237\u7aef\u7684\u6d88\u606f\u5e76\u5c06\u5176\u56de\u663e\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<h4>\u9009\u62e9\u5408\u9002\u7684ASGI\u670d\u52a1\u5668<\/h4>\n<p>\u76ee\u524d\u5e02\u9762\u4e0a\u6709\u591a\u4e2aASGI\u670d\u52a1\u5668\u53ef\u4f9b\u9009\u62e9&#xff0c;\u5982uvicorn\u3001daphne\u548chypercorn\u3002\u6bcf\u4e2a\u670d\u52a1\u5668\u90fd\u6709\u5176\u7279\u70b9\u548c\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>uvicorn&#xff1a;\u57fa\u4e8euvloop\u548chttptools&#xff0c;\u6027\u80fd\u4f18\u5f02&#xff0c;\u9002\u5408\u5927\u591a\u6570\u5e94\u7528\u573a\u666f\u3002<\/li>\n<li>daphne&#xff1a;\u7531Django\u56e2\u961f\u5f00\u53d1&#xff0c;\u4e13\u95e8\u7528\u4e8eDjango Channels\u9879\u76ee\u3002<\/li>\n<li>hypercorn&#xff1a;\u652f\u6301HTTP\/2\u548cASGI 3.0&#xff0c;\u9002\u5408\u9700\u8981\u9ad8\u7ea7\u534f\u8bae\u652f\u6301\u7684\u5e94\u7528\u3002<\/li>\n<\/ul>\n<h4>\u603b\u7ed3<\/h4>\n<p>ASGI\u4f5c\u4e3aWSGI\u7684\u7ee7\u4efb\u8005&#xff0c;\u4e3aPython Web\u5f00\u53d1\u5e26\u6765\u4e86\u5f02\u6b65\u5904\u7406\u548c\u591a\u534f\u8bae\u652f\u6301\u7684\u80fd\u529b\u3002\u901a\u8fc7ASGI&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u6784\u5efa\u66f4\u9ad8\u6548\u3001\u66f4\u7075\u6d3b\u7684Web\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5c24\u5176\u662f\u5728\u5904\u7406\u9ad8\u5e76\u53d1\u548c\u5b9e\u65f6\u901a\u4fe1\u573a\u666f\u65f6\u3002\u901a\u8fc7\u672c\u6587\u7684\u8bb2\u89e3\u548c\u4ee3\u7801\u793a\u4f8b&#xff0c;\u5e0c\u671b\u4f60\u80fd\u66f4\u597d\u5730\u7406\u89e3ASGI\u7684\u5de5\u4f5c\u539f\u7406\u53ca\u5176\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\u3002<\/p>\n<h4>\u8fdb\u4e00\u6b65\u5b66\u4e60\u8d44\u6e90<\/h4>\n<ul>\n<li>ASGI\u5b98\u65b9\u6587\u6863&#xff1a;https:\/\/asgi.readthedocs.io\/<\/li>\n<li>Uvicorn\u6587\u6863&#xff1a;https:\/\/www.uvicorn.org\/<\/li>\n<li>Django Channels&#xff1a;https:\/\/channels.readthedocs.io\/<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u8d44\u6e90&#xff0c;\u4f60\u53ef\u4ee5\u6df1\u5165\u5b66\u4e60ASGI\u7684\u66f4\u591a\u7ec6\u8282&#xff0c;\u5e76\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u5e94\u7528\u8fd9\u4e9b\u77e5\u8bc6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf28\u6b21\u3002ASGI\u662fWSGI\u7684\u7ee7\u4efb\u8005\uff0c\u65e8\u5728\u63d0\u4f9b\u4e00\u4e2a\u5f02\u6b65\u7684\u3001\u652f\u6301\u591a\u79cd\u534f\u8bae\u7684\u63a5\u53e3\u3002\u4e0eWSGI\u4e0d\u540c\uff0cASGI\u4e0d\u4ec5\u652f\u6301\u4f20\u7edf\u7684HTTP\u8bf7\u6c42\uff0c\u8fd8\u652f\u6301WebSocket\u3001HTTP\/2\u4ee5\u53ca\u672a\u6765\u7684\u534f\u8bae\u3002ASGI\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u8ba9Python Web\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u5904\u7406\u5f02\u6b65\u8bf7\u6c42\uff0c\u4ece\u800c\u63d0\u5347\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002ASGI\u4f5c\u4e3aWSGI\u7684\u7ee7\u4efb\u8005\uff0c\u4e3aPython Web\u5f00\u53d1\u5e26\u6765\u4e86\u5f02\u6b65\u5904\u7406\u548c\u591a\u534f\u8bae\u652f\u6301\u7684\u80fd\u529b\u3002\u901a\u8fc7ASGI\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6784\u5efa\u66f4\u9ad8\u6548\u3001\u66f4\u7075\u6d3b\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u9ad8\u5e76\u53d1\u548c\u5b9e\u65f6\u901a\u4fe1\u573a\u666f\u65f6\u3002_asgi \u670d\u52a1\u5668<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[43,44],"topic":[],"class_list":["post-29099","post","type-post","status-publish","format-standard","hentry","category-server","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/29099.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf28\u6b21\u3002ASGI\u662fWSGI\u7684\u7ee7\u4efb\u8005\uff0c\u65e8\u5728\u63d0\u4f9b\u4e00\u4e2a\u5f02\u6b65\u7684\u3001\u652f\u6301\u591a\u79cd\u534f\u8bae\u7684\u63a5\u53e3\u3002\u4e0eWSGI\u4e0d\u540c\uff0cASGI\u4e0d\u4ec5\u652f\u6301\u4f20\u7edf\u7684HTTP\u8bf7\u6c42\uff0c\u8fd8\u652f\u6301WebSocket\u3001HTTP\/2\u4ee5\u53ca\u672a\u6765\u7684\u534f\u8bae\u3002ASGI\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u8ba9Python Web\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u5904\u7406\u5f02\u6b65\u8bf7\u6c42\uff0c\u4ece\u800c\u63d0\u5347\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002ASGI\u4f5c\u4e3aWSGI\u7684\u7ee7\u4efb\u8005\uff0c\u4e3aPython Web\u5f00\u53d1\u5e26\u6765\u4e86\u5f02\u6b65\u5904\u7406\u548c\u591a\u534f\u8bae\u652f\u6301\u7684\u80fd\u529b\u3002\u901a\u8fc7ASGI\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6784\u5efa\u66f4\u9ad8\u6548\u3001\u66f4\u7075\u6d3b\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u9ad8\u5e76\u53d1\u548c\u5b9e\u65f6\u901a\u4fe1\u573a\u666f\u65f6\u3002_asgi \u670d\u52a1\u5668\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/29099.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-19T21:41:14+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/29099.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/29099.html\",\"name\":\"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T21:41:14+00:00\",\"dateModified\":\"2025-04-19T21:41:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/29099.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/29099.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/29099.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/29099.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf28\u6b21\u3002ASGI\u662fWSGI\u7684\u7ee7\u4efb\u8005\uff0c\u65e8\u5728\u63d0\u4f9b\u4e00\u4e2a\u5f02\u6b65\u7684\u3001\u652f\u6301\u591a\u79cd\u534f\u8bae\u7684\u63a5\u53e3\u3002\u4e0eWSGI\u4e0d\u540c\uff0cASGI\u4e0d\u4ec5\u652f\u6301\u4f20\u7edf\u7684HTTP\u8bf7\u6c42\uff0c\u8fd8\u652f\u6301WebSocket\u3001HTTP\/2\u4ee5\u53ca\u672a\u6765\u7684\u534f\u8bae\u3002ASGI\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u8ba9Python Web\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u5904\u7406\u5f02\u6b65\u8bf7\u6c42\uff0c\u4ece\u800c\u63d0\u5347\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002ASGI\u4f5c\u4e3aWSGI\u7684\u7ee7\u4efb\u8005\uff0c\u4e3aPython Web\u5f00\u53d1\u5e26\u6765\u4e86\u5f02\u6b65\u5904\u7406\u548c\u591a\u534f\u8bae\u652f\u6301\u7684\u80fd\u529b\u3002\u901a\u8fc7ASGI\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6784\u5efa\u66f4\u9ad8\u6548\u3001\u66f4\u7075\u6d3b\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u9ad8\u5e76\u53d1\u548c\u5b9e\u65f6\u901a\u4fe1\u573a\u666f\u65f6\u3002_asgi \u670d\u52a1\u5668","og_url":"https:\/\/www.wsisp.com\/helps\/29099.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T21:41:14+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/29099.html","url":"https:\/\/www.wsisp.com\/helps\/29099.html","name":"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T21:41:14+00:00","dateModified":"2025-04-19T21:41:14+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/29099.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/29099.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/29099.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4ec0\u4e48\u662fASGI\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/29099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=29099"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/29099\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=29099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=29099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=29099"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=29099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}