{"id":48800,"date":"2025-07-30T13:27:00","date_gmt":"2025-07-30T05:27:00","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/48800.html"},"modified":"2025-07-30T13:27:00","modified_gmt":"2025-07-30T05:27:00","slug":"%e6%b7%b1%e5%85%a5%e5%89%96%e6%9e%90-uvicorn%ef%bc%9a%e4%bb%8e-asgi-%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%a0%b8%e5%bf%83%e5%88%b0%e9%ab%98%e6%80%a7%e8%83%bd%e9%83%a8%e7%bd%b2%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/48800.html","title":{"rendered":"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5"},"content":{"rendered":"<p>\u5f53\u6211\u4eec\u5728\u6784\u5efa\u73b0\u4ee3\u5f02\u6b65 Web \u5e94\u7528\u65f6&#xff0c;\u662f\u5426\u66fe\u4e3a\u5bfb\u627e\u4e00\u4e2a\u65e2\u80fd\u53d1\u6325 Python \u5f02\u6b65\u4f18\u52bf&#xff0c;\u53c8\u80fd\u517c\u987e\u5f00\u53d1\u6548\u7387\u4e0e\u751f\u4ea7\u6027\u80fd\u7684\u670d\u52a1\u5668\u800c\u82e6\u607c&#xff1f;\u4eca\u5929\u8981\u804a\u7684 Uvicorn&#xff0c;\u6b63\u662f\u8fd9\u6837\u4e00\u4e2a\u57fa\u4e8e ASGI \u89c4\u8303\u7684\u9ad8\u6027\u80fd Web \u670d\u52a1\u5668\u5b9e\u73b0&#xff0c;\u5b83\u4e0d\u4ec5\u586b\u8865\u4e86 Python \u5f02\u6b65\u6846\u67b6\u5e95\u5c42\u63a5\u53e3\u7684\u7a7a\u767d&#xff0c;\u8fd8\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4ece\u5f00\u53d1\u5230\u90e8\u7f72\u7684\u5168\u6d41\u7a0b\u89e3\u51b3\u65b9\u6848\u3002\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c31\u4ece\u6838\u5fc3\u6982\u5ff5\u5230\u5b9e\u6218\u5e94\u7528&#xff0c;\u4e00\u6b65\u6b65\u63ed\u5f00 Uvicorn \u7684\u6280\u672f\u9762\u7eb1\u3002<\/p>\n<h3>\u4e00\u3001Uvicorn \u4e0e ASGI&#xff1a;\u5f02\u6b65\u751f\u6001\u7684\u5173\u952e\u62fc\u56fe<\/h3>\n<p>Python \u7684\u5f02\u6b65\u7f16\u7a0b\u751f\u6001\u53d1\u5c55\u8fc5\u731b&#xff0c;\u4f46\u957f\u671f\u4ee5\u6765\u7f3a\u4e4f\u4e00\u4e2a\u7edf\u4e00\u7684\u5f02\u6b65\u670d\u52a1\u5668\u4e0e\u5e94\u7528\u63a5\u53e3\u6807\u51c6\u3002\u76f4\u5230 ASGI&#xff08;Asynchronous Server Gateway Interface&#xff09;\u89c4\u8303\u7684\u51fa\u73b0&#xff0c;\u624d\u771f\u6b63\u6253\u901a\u4e86\u5f02\u6b65\u6846\u67b6\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u58c1\u5792\u3002Uvicorn \u4f5c\u4e3a ASGI \u7684\u4f18\u79c0\u5b9e\u73b0&#xff0c;\u76ee\u524d\u5df2\u652f\u6301 HTTP\/1.1 \u548c WebSocket \u534f\u8bae&#xff0c;\u6210\u4e3a\u8fde\u63a5\u5f02\u6b65\u6846\u67b6\u4e0e\u5e95\u5c42\u670d\u52a1\u7684\u91cd\u8981\u6865\u6881\u3002<\/p>\n<h4>\u4e3a\u4ec0\u4e48 ASGI \u5982\u6b64\u91cd\u8981&#xff1f;<\/h4>\n<p>\u5bf9\u6bd4\u4f20\u7edf\u7684 WSGI \u63a5\u53e3&#xff0c;ASGI \u6700\u5927\u7684\u7a81\u7834\u5728\u4e8e\u5bf9\u957f\u8fde\u63a5\u573a\u666f\u7684\u652f\u6301\u3002\u5728 WSGI \u65f6\u4ee3&#xff0c;\u6211\u4eec\u5904\u7406 WebSocket \u6216\u957f\u8f6e\u8be2\u8bf7\u6c42\u65f6\u5e38\u5e38\u6349\u895f\u89c1\u8098&#xff0c;\u800c ASGI \u901a\u8fc7\u5f02\u6b65\u6a21\u578b\u8ba9\u6211\u4eec\u80fd\u591f\u8f7b\u677e\u5e94\u5bf9\u8fd9\u4e9b\u573a\u666f\u3002\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u5f53\u6211\u4eec\u5f00\u53d1\u4e00\u4e2a\u5b9e\u65f6\u804a\u5929\u5e94\u7528\u65f6&#xff0c;ASGI \u53ef\u4ee5\u8ba9\u670d\u52a1\u5668\u540c\u65f6\u5904\u7406\u591a\u4e2a WebSocket \u8fde\u63a5&#xff0c;\u800c\u4e0d\u4f1a\u56e0\u67d0\u4e00\u8fde\u63a5\u7684\u963b\u585e\u5f71\u54cd\u6574\u4f53\u6027\u80fd&#xff0c;\u8fd9\u6b63\u662f\u73b0\u4ee3\u9ad8\u5e76\u53d1\u5e94\u7528\u6240\u6025\u9700\u7684\u80fd\u529b\u3002<\/p>\n<h3>\u4e8c\u3001\u5feb\u901f\u4e0a\u624b&#xff1a;\u4ece\u5b89\u88c5\u5230\u7b2c\u4e00\u4e2a Hello World<\/h3>\n<h4>\u4e24\u6b65\u5b8c\u6210\u73af\u5883\u642d\u5efa<\/h4>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 pip \u8f7b\u677e\u5b89\u88c5 Uvicorn&#xff0c;\u6839\u636e\u4e0d\u540c\u9700\u6c42\u6709\u4e24\u79cd\u5b89\u88c5\u65b9\u5f0f&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>\u57fa\u7840\u5b89\u88c5&#xff08;\u7eaf Python \u4f9d\u8d56&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p>python<\/p>\n<p>pip install uvicorn<\/p>\n<ul>\n<li>\u6807\u51c6\u5b89\u88c5&#xff08;\u542b Cython \u4f18\u5316\u4f9d\u8d56&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p>python<\/p>\n<p>pip install &#039;uvicorn[standard]&#039;<\/p>\n<p>\u6807\u51c6\u5b89\u88c5\u4f1a\u5e26\u6765\u663e\u8457\u7684\u6027\u80fd\u63d0\u5347&#xff1a;\u5b83\u4f1a\u4f18\u5148\u5b89\u88c5 uvloop&#xff08;Cython \u5b9e\u73b0\u7684\u9ad8\u6027\u80fd\u4e8b\u4ef6\u5faa\u73af&#xff0c;\u66ff\u6362\u5185\u7f6e asyncio&#xff09;\u548c httptools&#xff08;\u4f18\u5316 HTTP \u534f\u8bae\u5904\u7406&#xff09;\u3002\u5b9e\u6d4b\u663e\u793a&#xff0c;\u4f7f\u7528 uvloop \u540e\u4e8b\u4ef6\u5faa\u73af\u6548\u7387\u53ef\u63d0\u5347 3-5 \u500d&#xff0c;\u800c httptools \u5904\u7406 HTTP \u8bf7\u6c42\u7684\u901f\u5ea6\u4e5f\u8fdc\u9ad8\u4e8e\u7eaf Python \u5b9e\u73b0\u7684 h11\u3002<\/p>\n<h4>5 \u884c\u4ee3\u7801\u521b\u5efa\u7b2c\u4e00\u4e2a ASGI \u5e94\u7528<\/h4>\n<p>python<\/p>\n<p># main.py<br \/>\nasync def app(scope, receive, send):<br \/>\n    assert scope[&#039;type&#039;] &#061;&#061; &#039;http&#039;<br \/>\n    await send({<br \/>\n        &#039;type&#039;: &#039;http.response.start&#039;,<br \/>\n        &#039;status&#039;: 200,<br \/>\n        &#039;headers&#039;: [(b&#039;content-type&#039;, b&#039;text\/plain&#039;), (b&#039;content-length&#039;, b&#039;13&#039;)]<br \/>\n    })<br \/>\n    await send({<br \/>\n        &#039;type&#039;: &#039;http.response.body&#039;,<br \/>\n        &#039;body&#039;: b&#039;Hello, world!&#039;<br \/>\n    })<\/p>\n<p>\u8fd9\u4e2a\u6781\u7b80\u5e94\u7528\u5305\u542b\u4e86 ASGI \u5e94\u7528\u7684\u6838\u5fc3\u8981\u7d20&#xff1a;<\/p>\n<\/p>\n<ul>\n<li>scope&#xff1a;\u5305\u542b\u8bf7\u6c42\u7c7b\u578b\u3001\u534f\u8bae\u3001\u8def\u5f84\u7b49\u8fde\u63a5\u4fe1\u606f&#xff0c;\u5178\u578b HTTP \u8bf7\u6c42\u7684 scope \u7ed3\u6784&#xff1a;<\/li>\n<\/ul>\n<p>{<br \/>\n    &#039;type&#039;: &#039;http&#039;,<br \/>\n    &#039;scheme&#039;: &#039;http&#039;,<br \/>\n    &#039;root_path&#039;: &#039;&#039;,<br \/>\n    &#039;server&#039;: (&#039;127.0.0.1&#039;, 8000),<br \/>\n    &#039;http_version&#039;: &#039;1.1&#039;,<br \/>\n    &#039;method&#039;: &#039;GET&#039;,<br \/>\n    &#039;path&#039;: &#039;\/&#039;,<br \/>\n    &#039;headers&#039;: [(b&#039;host&#039;, b&#039;127.0.0.1:8000&#039;), &#8230;]<br \/>\n}<\/p>\n<ul>\n<li>receive&#xff1a;\u63a5\u6536\u670d\u52a1\u5668\u6d88\u606f\u7684\u901a\u9053<\/li>\n<li>send&#xff1a;\u5411\u670d\u52a1\u5668\u53d1\u9001\u54cd\u5e94\u7684\u901a\u9053<br \/>\n\u8fd0\u884c\u65f6\u53ea\u9700\u5728\u547d\u4ee4\u884c\u6267\u884c&#xff1a;<\/li>\n<\/ul>\n<p>bash<\/p>\n<p>uvicorn main:app<\/p>\n<p>\u9ed8\u8ba4\u4f1a\u5728127.0.0.1:8000\u542f\u52a8\u670d\u52a1&#xff0c;\u6d4f\u89c8\u5668\u8bbf\u95ee\u5373\u53ef\u770b\u5230 &#034;Hello, world!&#034;\u3002\u8fd9\u91cc\u7684main:app\u8868\u793a\u4ece main \u6a21\u5757\u4e2d\u52a0\u8f7d\u540d\u4e3a app \u7684 ASGI \u5e94\u7528\u5b9e\u4f8b\u3002<\/p>\n<h3>\u4e09\u3001\u8fdb\u9636\u914d\u7f6e&#xff1a;\u547d\u4ee4\u884c\u9009\u9879\u7684\u6df1\u5ea6\u89e3\u6790<\/h3>\n<p>Uvicorn \u7684\u547d\u4ee4\u884c\u5de5\u5177\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u914d\u7f6e\u9009\u9879&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u5206\u4e3a\u51e0\u5927\u529f\u80fd\u6a21\u5757&#xff1a;<\/p>\n<h4>\u7f51\u7edc\u4e0e\u670d\u52a1\u5668\u914d\u7f6e<\/h4>\n<ul>\n<li>&#8211;host\/&#8211;port&#xff1a;\u6307\u5b9a\u7ed1\u5b9a\u7684\u4e3b\u673a\u548c\u7aef\u53e3&#xff08;\u9ed8\u8ba4 127.0.0.1:8000&#xff09;<\/li>\n<li>&#8211;uds&#xff1a;\u7ed1\u5b9a UNIX \u57df\u5957\u63a5\u5b57&#xff0c;\u9002\u7528\u4e8e\u5bb9\u5668\u73af\u5883<\/li>\n<li>&#8211;fd&#xff1a;\u4ece\u6587\u4ef6\u63cf\u8ff0\u7b26\u7ed1\u5b9a\u5957\u63a5\u5b57&#xff0c;\u652f\u6301\u8fdb\u7a0b\u95f4\u5957\u63a5\u5b57\u5171\u4eab<\/li>\n<\/ul>\n<h4>\u70ed\u91cd\u8f7d\u4e0e\u5f00\u53d1\u6548\u7387<\/h4>\n<ul>\n<li>&#8211;reload&#xff1a;\u542f\u7528\u81ea\u52a8\u91cd\u8f7d&#xff0c;\u4ee3\u7801\u53d8\u66f4\u540e\u81ea\u52a8\u91cd\u542f\u670d\u52a1<\/li>\n<li>&#8211;reload-dir&#xff1a;\u663e\u5f0f\u6307\u5b9a\u76d1\u63a7\u76ee\u5f55<\/li>\n<li>&#8211;reload-delay&#xff1a;\u91cd\u8f7d\u68c0\u67e5\u95f4\u9694&#xff08;\u9ed8\u8ba4 0.25 \u79d2&#xff09;<\/li>\n<\/ul>\n<h4>\u591a\u8fdb\u7a0b\u4e0e\u6027\u80fd\u4f18\u5316<\/h4>\n<ul>\n<li>&#8211;workers&#xff1a;\u5de5\u4f5c\u8fdb\u7a0b\u6570&#xff0c;\u9ed8\u8ba4 1 \u4e2a&#xff0c;\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u8bbe\u4e3aCPU\u6838\u5fc3\u6570*2&#043;1<\/li>\n<li>&#8211;loop&#xff1a;\u4e8b\u4ef6\u5faa\u73af\u7c7b\u578b&#xff08;auto\/asyncio\/uvloop&#xff09;&#xff0c;\u63a8\u8350\u8bbe\u4e3a uvloop<\/li>\n<li>&#8211;http&#xff1a;HTTP \u534f\u8bae\u5b9e\u73b0&#xff08;auto\/h11\/httptools&#xff09;&#xff0c;httptools \u6027\u80fd\u66f4\u4f18<\/li>\n<\/ul>\n<h4>\u534f\u8bae\u4e0e\u8fde\u63a5\u63a7\u5236<\/h4>\n<ul>\n<li>&#8211;ws&#xff1a;WebSocket \u534f\u8bae\u5b9e\u73b0&#xff08;\u9ed8\u8ba4 auto&#xff09;<\/li>\n<li>&#8211;ws-max-size&#xff1a;\u6700\u5927 WebSocket \u6d88\u606f\u5927\u5c0f&#xff08;\u9ed8\u8ba4 16MB&#xff09;<\/li>\n<li>&#8211;timeout-keep-alive&#xff1a;\u4fdd\u6301\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4&#xff08;\u9ed8\u8ba4 5 \u79d2&#xff09;<\/li>\n<\/ul>\n<h4>\u5b89\u5168\u4e0e\u8bc1\u4e66\u914d\u7f6e<\/h4>\n<ul>\n<li>&#8211;ssl-keyfile\/&#8211;ssl-certfile&#xff1a;HTTPS \u8bc1\u4e66\u914d\u7f6e<\/li>\n<li>&#8211;forwarded-allow-ips&#xff1a;\u4fe1\u4efb\u7684\u4ee3\u7406 IP \u5217\u8868&#xff0c;\u9632\u6b62\u8bf7\u6c42\u4f2a\u9020<\/li>\n<\/ul>\n<h4>\u65e5\u5fd7\u4e0e\u76d1\u63a7<\/h4>\n<ul>\n<li>&#8211;log-level&#xff1a;\u65e5\u5fd7\u7ea7\u522b&#xff08;info\/debug\/warning \u7b49&#xff09;<\/li>\n<li>&#8211;access-log&#xff1a;\u542f\u7528\u8bbf\u95ee\u65e5\u5fd7<\/li>\n<li>&#8211;log-config&#xff1a;\u81ea\u5b9a\u4e49\u65e5\u5fd7\u914d\u7f6e\u6587\u4ef6&#xff0c;\u652f\u6301.yaml\/.json \u7b49\u683c\u5f0f<\/li>\n<\/ul>\n<h3>\u56db\u3001\u7f16\u7a0b\u5f0f\u542f\u52a8&#xff1a;\u7075\u6d3b\u63a7\u5236\u670d\u52a1\u751f\u547d\u5468\u671f<\/h3>\n<p>\u9664\u4e86\u547d\u4ee4\u884c&#xff0c;\u6211\u4eec\u8fd8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u76f4\u63a5\u542f\u52a8 Uvicorn&#xff0c;\u8fd9\u5728\u9700\u8981\u52a8\u6001\u914d\u7f6e\u6216\u96c6\u6210\u5230\u5176\u4ed6\u7cfb\u7edf\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h4>\u7b80\u5355\u573a\u666f&#xff1a;uvicorn.run ()<\/h4>\n<p>python<\/p>\n<p>import uvicorn<\/p>\n<p>async def app(scope, receive, send):<br \/>\n    # \u5e94\u7528\u903b\u8f91&#8230;<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    uvicorn.run(&#034;main:app&#034;, port&#061;5000, log_level&#061;&#034;info&#034;)<\/p>\n<h4>\u590d\u6742\u914d\u7f6e&#xff1a;Config \u4e0e Server \u5b9e\u4f8b<\/h4>\n<p>python<\/p>\n<p>import uvicorn<\/p>\n<p>async def app(scope, receive, send):<br \/>\n    # \u5e94\u7528\u903b\u8f91&#8230;<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    config &#061; uvicorn.Config(&#034;main:app&#034;, port&#061;5000, log_level&#061;&#034;info&#034;, workers&#061;4)<br \/>\n    server &#061; uvicorn.Server(config)<br \/>\n    server.run()<\/p>\n<h4>\u5f02\u6b65\u73af\u5883\u96c6\u6210&#xff1a;serve () \u65b9\u6cd5<\/h4>\n<p>python<\/p>\n<p>import asyncio<br \/>\nimport uvicorn<\/p>\n<p>async def app(scope, receive, send):<br \/>\n    # \u5e94\u7528\u903b\u8f91&#8230;<\/p>\n<p>async def main():<br \/>\n    config &#061; uvicorn.Config(&#034;main:app&#034;, port&#061;5000)<br \/>\n    server &#061; uvicorn.Server(config)<br \/>\n    await server.serve()<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    asyncio.run(main())<\/p>\n<h3>\u4e94\u3001\u751f\u4ea7\u90e8\u7f72&#xff1a;\u4e0e Gunicorn \u7684\u9ec4\u91d1\u7ec4\u5408<\/h3>\n<p>\u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u63a8\u8350\u4f7f\u7528 Uvicorn \u4e0e Gunicorn \u7ed3\u5408\u7684\u90e8\u7f72\u65b9\u6848\u3002Gunicorn \u4f5c\u4e3a\u6210\u719f\u7684\u8fdb\u7a0b\u7ba1\u7406\u5668&#xff0c;\u63d0\u4f9b\u4e86\u70ed\u91cd\u542f\u3001\u52a8\u6001\u6269\u7f29\u5bb9\u7b49\u4f01\u4e1a\u7ea7\u529f\u80fd&#xff0c;\u800c Uvicorn \u5219\u53d1\u6325 ASGI \u7684\u9ad8\u6027\u80fd\u4f18\u52bf\u3002<\/p>\n<h4>\u5b89\u88c5 uvicorn-worker<\/h4>\n<p>bash<\/p>\n<p>pip install uvicorn-worker<\/p>\n<h4>\u5178\u578b\u90e8\u7f72\u547d\u4ee4<\/h4>\n<p>bash<\/p>\n<p>gunicorn example:app -w 4 -k uvicorn.workers.UvicornWorker<\/p>\n<ul>\n<li>-w 4&#xff1a;4 \u4e2a\u5de5\u4f5c\u8fdb\u7a0b<\/li>\n<li>-k uvicorn.workers.UvicornWorker&#xff1a;\u4f7f\u7528 Uvicorn \u5de5\u4f5c\u7c7b<\/li>\n<li>\u5982\u9700 PyPy \u517c\u5bb9&#xff0c;\u53ef\u4f7f\u7528UvicornH11Worker<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u90e8\u7f72\u65b9\u5f0f\u8ba9\u6211\u4eec\u65e2\u80fd\u4eab\u53d7 Gunicorn \u5b8c\u5584\u7684\u8fdb\u7a0b\u7ba1\u7406\u80fd\u529b&#xff0c;\u53c8\u80fd\u5229\u7528 Uvicorn \u7684\u5f02\u6b65\u9ad8\u6027\u80fd&#xff0c;\u7279\u522b\u9002\u5408\u9ad8\u5e76\u53d1\u3001\u957f\u8fde\u63a5\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<h3><\/h3>\n<h3>\u516d\u3001ASGI \u751f\u6001\u5168\u666f&#xff1a;\u670d\u52a1\u5668\u4e0e\u6846\u67b6\u77e9\u9635<\/h3>\n<h4>\u5176\u4ed6 ASGI \u670d\u52a1\u5668<\/h4>\n<ul>\n<li>Daphne&#xff1a;\u9996\u4e2a ASGI \u670d\u52a1\u5668\u5b9e\u73b0&#xff0c;\u652f\u6301 HTTP\/1.1\u3001HTTP\/2 \u548c WebSocket&#xff0c;\u5e38\u7528\u4e8e Django Channels<\/li>\n<li>Hypercorn&#xff1a;\u652f\u6301 HTTP\/1.1\u3001HTTP\/2\u3001HTTP\/3 \u548c WebSocket&#xff0c;\u6027\u80fd\u8868\u73b0\u4f18\u5f02<\/li>\n<\/ul>\n<h4>\u4e3b\u6d41 ASGI \u6846\u67b6<\/h4>\n<ul>\n<li>Starlette&#xff1a;\u8f7b\u91cf\u7ea7 ASGI \u6846\u67b6&#xff0c;\u9ad8\u6027\u80fd\u5f02\u6b65\u670d\u52a1\u9996\u9009<\/li>\n<li>FastAPI&#xff1a;\u57fa\u4e8e Starlette \u548c Pydantic&#xff0c;API \u5f00\u53d1\u6548\u7387\u795e\u5668<\/li>\n<li>Django Channels&#xff1a;\u4e3a Django \u6dfb\u52a0\u5f02\u6b65\u80fd\u529b&#xff0c;\u652f\u6301 WebSocket \u548c\u957f\u8fde\u63a5<\/li>\n<li>Quart&#xff1a;Flask \u98ce\u683c\u7684 ASGI \u6846\u67b6&#xff0c;\u63a5\u53e3\u517c\u5bb9 WSGI \u5e94\u7528<\/li>\n<li>BlackSheep&#xff1a;\u652f\u6301\u4f9d\u8d56\u6ce8\u5165\u548c OpenAPI \u6587\u6863\u751f\u6210<\/li>\n<li>Litestar&#xff1a;\u529f\u80fd\u5168\u9762\u7684 ASGI \u6846\u67b6&#xff0c;\u96c6\u6210 ORM \u548c\u8ba4\u8bc1\u7cfb\u7edf<\/li>\n<\/ul>\n<h3>\u7ed3\u8bed&#xff1a;Uvicorn \u5f00\u542f\u5f02\u6b65\u5f00\u53d1\u65b0\u8303\u5f0f<\/h3>\n<p>\u901a\u8fc7\u6df1\u5165\u4e86\u89e3 Uvicorn \u7684\u6838\u5fc3\u673a\u5236\u4e0e\u5b9e\u8df5\u5e94\u7528&#xff0c;\u6211\u4eec\u53ef\u4ee5\u770b\u5230 ASGI \u89c4\u8303\u5982\u4f55\u4e3a Python \u5f02\u6b65\u5f00\u53d1\u5e26\u6765\u7edf\u4e00\u7684\u57fa\u7840\u8bbe\u65bd\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u9636\u6bb5\u7684\u70ed\u91cd\u8f7d\u6548\u7387&#xff0c;\u8fd8\u662f\u751f\u4ea7\u73af\u5883\u7684\u9ad8\u6027\u80fd\u90e8\u7f72&#xff0c;Uvicorn \u90fd\u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5728\u6784\u5efa\u4e0b\u4e00\u4e2a\u9ad8\u5e76\u53d1 Web \u5e94\u7528\u6216\u5b9e\u65f6\u670d\u52a1\u65f6&#xff0c;\u4e0d\u59a8\u5c1d\u8bd5\u7528 Uvicorn \u4f5c\u4e3a\u4f60\u7684 ASGI \u5f15\u64ce&#xff0c;\u4f53\u9a8c\u5f02\u6b65\u7f16\u7a0b\u7684\u771f\u6b63\u5a01\u529b\u3002<\/p>\n<p>\u5982\u679c\u672c\u6587\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u522b\u5fd8\u4e86\u70b9\u8d5e\u6536\u85cf&#xff0c;\u5173\u6ce8\u6211&#xff0c;\u4e00\u8d77\u63a2\u7d22\u66f4\u9ad8\u6548\u7684\u5f00\u53d1\u65b9\u5f0f&#xff5e;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb816\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u901a\u8fc7\u6df1\u5165\u4e86\u89e3 Uvicorn \u7684\u6838\u5fc3\u673a\u5236\u4e0e\u5b9e\u8df5\u5e94\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 ASGI \u89c4\u8303\u5982\u4f55\u4e3a Python \u5f02\u6b65\u5f00\u53d1\u5e26\u6765\u7edf\u4e00\u7684\u57fa\u7840\u8bbe\u65bd\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u9636\u6bb5\u7684\u70ed\u91cd\u8f7d\u6548\u7387\uff0c\u8fd8\u662f\u751f\u4ea7\u73af\u5883\u7684\u9ad8\u6027\u80fd\u90e8\u7f72\uff0cUvicorn \u90fd\u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5728\u6784\u5efa\u4e0b\u4e00\u4e2a\u9ad8\u5e76\u53d1 Web \u5e94\u7528\u6216\u5b9e\u65f6\u670d\u52a1\u65f6\uff0c\u4e0d\u59a8\u5c1d\u8bd5\u7528 Uvicorn \u4f5c\u4e3a\u4f60\u7684 ASGI \u5f15\u64ce\uff0c\u4f53\u9a8c\u5f02\u6b65\u7f16\u7a0b\u7684\u771f\u6b63\u5a01\u529b\u3002_uvicorn<\/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":[4725,2254,43],"topic":[],"class_list":["post-48800","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-uvicorn","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5 - \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\/48800.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb816\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u901a\u8fc7\u6df1\u5165\u4e86\u89e3 Uvicorn \u7684\u6838\u5fc3\u673a\u5236\u4e0e\u5b9e\u8df5\u5e94\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 ASGI \u89c4\u8303\u5982\u4f55\u4e3a Python \u5f02\u6b65\u5f00\u53d1\u5e26\u6765\u7edf\u4e00\u7684\u57fa\u7840\u8bbe\u65bd\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u9636\u6bb5\u7684\u70ed\u91cd\u8f7d\u6548\u7387\uff0c\u8fd8\u662f\u751f\u4ea7\u73af\u5883\u7684\u9ad8\u6027\u80fd\u90e8\u7f72\uff0cUvicorn \u90fd\u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5728\u6784\u5efa\u4e0b\u4e00\u4e2a\u9ad8\u5e76\u53d1 Web \u5e94\u7528\u6216\u5b9e\u65f6\u670d\u52a1\u65f6\uff0c\u4e0d\u59a8\u5c1d\u8bd5\u7528 Uvicorn \u4f5c\u4e3a\u4f60\u7684 ASGI \u5f15\u64ce\uff0c\u4f53\u9a8c\u5f02\u6b65\u7f16\u7a0b\u7684\u771f\u6b63\u5a01\u529b\u3002_uvicorn\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/48800.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T05:27:00+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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/48800.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/48800.html\",\"name\":\"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T05:27:00+00:00\",\"dateModified\":\"2025-07-30T05:27:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/48800.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/48800.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/48800.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5\"}]},{\"@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":"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5 - \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\/48800.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb816\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u901a\u8fc7\u6df1\u5165\u4e86\u89e3 Uvicorn \u7684\u6838\u5fc3\u673a\u5236\u4e0e\u5b9e\u8df5\u5e94\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 ASGI \u89c4\u8303\u5982\u4f55\u4e3a Python \u5f02\u6b65\u5f00\u53d1\u5e26\u6765\u7edf\u4e00\u7684\u57fa\u7840\u8bbe\u65bd\u3002\u65e0\u8bba\u662f\u5f00\u53d1\u9636\u6bb5\u7684\u70ed\u91cd\u8f7d\u6548\u7387\uff0c\u8fd8\u662f\u751f\u4ea7\u73af\u5883\u7684\u9ad8\u6027\u80fd\u90e8\u7f72\uff0cUvicorn \u90fd\u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5728\u6784\u5efa\u4e0b\u4e00\u4e2a\u9ad8\u5e76\u53d1 Web \u5e94\u7528\u6216\u5b9e\u65f6\u670d\u52a1\u65f6\uff0c\u4e0d\u59a8\u5c1d\u8bd5\u7528 Uvicorn \u4f5c\u4e3a\u4f60\u7684 ASGI \u5f15\u64ce\uff0c\u4f53\u9a8c\u5f02\u6b65\u7f16\u7a0b\u7684\u771f\u6b63\u5a01\u529b\u3002_uvicorn","og_url":"https:\/\/www.wsisp.com\/helps\/48800.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T05:27:00+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/48800.html","url":"https:\/\/www.wsisp.com\/helps\/48800.html","name":"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T05:27:00+00:00","dateModified":"2025-07-30T05:27:00+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/48800.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/48800.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/48800.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6df1\u5165\u5256\u6790 Uvicorn\uff1a\u4ece ASGI \u670d\u52a1\u5668\u6838\u5fc3\u5230\u9ad8\u6027\u80fd\u90e8\u7f72\u5b9e\u8df5"}]},{"@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\/48800","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=48800"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/48800\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=48800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=48800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=48800"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=48800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}