{"id":123996,"date":"2026-11-08T16:56:46","date_gmt":"2026-11-08T08:56:46","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/123996.html"},"modified":"2026-11-08T16:56:46","modified_gmt":"2026-11-08T08:56:46","slug":"python-%e5%bc%82%e6%ad%a5%e5%bc%80%e5%8f%91%ef%bc%9a%e6%8f%90%e5%8d%87-ai-%e6%8e%a5%e5%8f%a3%e5%b9%b6%e5%8f%91%e5%a4%84%e7%90%86%e8%83%bd%e5%8a%9b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/123996.html","title":{"rendered":"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b"},"content":{"rendered":"<p>        \/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/<br \/>\n        #content_views .toc,<br \/>\n        \/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/<br \/>\n        #content_views.markdown_views &gt; p:empty:has(+ .toc),<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty,<br \/>\n        \/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/<br \/>\n        #content_views.htmledit_views #main-toc,<br \/>\n        #content_views.htmledit_views #hr-toc,<br \/>\n        #content_views.htmledit_views p[id*=\\&#8221;-toc\\&#8221;] {<br \/>\n          display: none !important;<br \/>\n        }<br \/>\n        \/* \u76ee\u5f55\u53bb\u6389\u540e\uff0c\u7d27\u8ddf\u7684\u9996\u4e2a\u6807\u9898\u4e0d\u518d\u591a\u51fa\u4e00\u5757\u4e0a\u8fb9\u8ddd *\/<br \/>\n        #content_views.markdown_views &gt; .toc + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + h4,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h4 {<br \/>\n          margin-top: 0 !important;<br \/>\n        }<\/p>\n<p>\u6458\u8981<br \/>\n\u540c\u6b65 requests \u8c03\u7528 LLM \u65f6\u7ebf\u7a0b\u5728\u7b49 IO&#xff0c;Gunicorn 32 \u5e76\u53d1\u4e0b\u5b9e\u6d4b QPS \u88ab\u9501\u6b7b\u5728 47&#xff0c;P99 \u5ef6\u8fdf 4.8 \u79d2\u3002\u9002\u5408\u5df2\u7528 FastAPI \u5c01\u88c5 AI \u63a5\u53e3\u3001\u4f46\u541e\u5410\u91cf\u5728\u5e76\u53d1\u538b\u6d4b\u4e2d\u89e6\u9876\u7684\u540e\u7aef\u4e0e\u7b97\u6cd5\u5de5\u7a0b\u5e08\u3002\u8bfb\u5b8c\u53ef\u83b7\u5f97 IO \u7b49\u5f85\u6d88\u9664\u3001\u963b\u585e\u8c03\u7528\u9694\u79bb\u3001\u8fde\u63a5\u6c60\u590d\u7528\u3001\u5e76\u53d1\u4e0a\u9650\u4fdd\u62a4\u4e0e\u7ed3\u6784\u5316\u5e76\u53d1\u5f02\u5e38\u4f20\u64ad\u7684\u5b8c\u6574\u5f02\u6b65\u6539\u9020\u8def\u5f84&#xff0c;\u4ee5\u53ca\u4ece 47 QPS \u5230 620 QPS \u7684\u9010\u5c42\u8c03\u4f18\u4f9d\u636e\u3002<\/p>\n<p>\u5173\u952e\u8bcd<br \/>\nPython \u5f02\u6b65\u3001asyncio\u3001FastAPI \u5e76\u53d1\u3001httpx \u8fde\u63a5\u6c60\u3001TaskGroup\u3001AI \u63a5\u53e3\u541e\u5410<\/p>\n<p>\u6b63\u6587<br \/>\n\u80cc\u666f\u4e0e\u95ee\u9898<br \/>\n\u540c\u6b65 requests \u8c03\u7528 LLM \u65f6&#xff0c;\u6bcf\u4e2a\u8bf7\u6c42\u72ec\u5360\u4e00\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u7f51\u7edc IO&#xff0c;\u7ebf\u7a0b\u6570\u51b3\u5b9a\u5e76\u53d1\u4e0a\u9650\u3002Gunicorn \u5f00 8 worker \u00d7 4 \u7ebf\u7a0b &#061; 32 \u5e76\u53d1&#xff0c;LLM \u5355\u6b21\u8c03\u7528\u5e73\u5747 680ms&#xff0c;\u7406\u8bba\u4e0a\u9650 32\/0.68 \u2248 47 QPS&#xff0c;\u5b9e\u6d4b\u5b8c\u5168\u543b\u5408\u3002\u9002\u7528\u4eba\u7fa4\u662f\u5df2\u7ecf\u8dd1\u901a FastAPI &#043; \u5927\u6a21\u578b\u63a5\u53e3\u3001\u4f46\u5728\u538b\u6d4b\u4e2d QPS \u65e0\u6cd5\u7ee7\u7eed\u63d0\u5347\u7684\u5f00\u53d1\u8005\u3002\u6838\u5fc3\u6536\u76ca\u662f\u8bc6\u522b\u5e76\u6d88\u9664 AI \u63a5\u53e3\u5e76\u53d1\u94fe\u8def\u4e0a\u56db\u7c7b\u76f8\u4e92\u72ec\u7acb\u7684\u74f6\u9888&#xff1a;IO \u7b49\u5f85\u3001\u540c\u6b65\u963b\u585e\u3001\u8fde\u63a5\u5f00\u9500\u4e0e\u65e0\u754c\u5e76\u53d1\u3002<\/p>\n<p>\u6838\u5fc3\u6982\u5ff5\u4e0e\u73af\u5883<br \/>\n\u4f9d\u8d56\u63a8\u8350\u7248\u672c\u8bf4\u660e<br \/>\nPython3.11&#043;asyncio.TaskGroup \u4e0e asyncio.timeout \u7684\u6700\u4f4e\u7248\u672c<br \/>\nFastAPI&gt;&#061;0.115\u5f02\u6b65\u8def\u7531\u4e0e\u4f9d\u8d56\u6ce8\u5165<br \/>\nhttpx&gt;&#061;0.27\u5f02\u6b65 HTTP \u5ba2\u6237\u7aef&#xff0c;\u8fde\u63a5\u6c60\u53ef\u663e\u5f0f\u914d\u7f6e<br \/>\nuvicorn&gt;&#061;0.30ASGI \u670d\u52a1\u5668<br \/>\nfastapi-stream-lease&#xff08;\u53ef\u9009&#xff09;&gt;&#061;0.6Redis \u652f\u6301\u7684\u6d41\u5f0f\u5e76\u53d1\u79df\u7ea6&#xff0c;\u8de8 worker \u751f\u6548<br \/>\n\u4e8b\u4ef6\u5faa\u73af&#xff1a;\u5355\u7ebf\u7a0b\u534f\u4f5c\u5f0f\u8c03\u5ea6\u5668&#xff0c;\u540c\u6b65\u963b\u585e\u8c03\u7528\u4f1a\u72ec\u5360\u5faa\u73af&#xff0c;\u6240\u6709\u534f\u7a0b\u505c\u6b62\u63a8\u8fdb\u3002<br \/>\nasyncio.to_thread&#xff1a;\u5c06\u540c\u6b65\u963b\u585e\u51fd\u6570\u63d0\u4ea4\u5230\u9ed8\u8ba4\u7ebf\u7a0b\u6c60&#xff0c;\u8fd4\u56de\u534f\u7a0b&#xff1b;\u7ebf\u7a0b\u6c60\u4e0a\u9650\u4e3a min(32, os.cpu_count() &#043; 4)&#xff0c;\u4e0d\u968f\u8d1f\u8f7d\u5f39\u6027\u4f38\u7f29\u3002<br \/>\n\u8fde\u63a5\u6c60&#xff1a;HTTP \u5ba2\u6237\u7aef\u590d\u7528 TCP\/TLS \u8fde\u63a5&#xff0c;\u907f\u514d\u6bcf\u6b21\u8c03\u7528\u91cd\u590d\u63e1\u624b\u3002httpx \u9ed8\u8ba4 keepalive_expiry \u4ec5 5 \u79d2&#xff0c;LLM \u8c03\u7528\u95f4\u9694\u8d85\u8fc7\u8be5\u9608\u503c\u65f6\u8fde\u63a5\u88ab\u56de\u6536&#xff0c;\u4e0b\u4e00\u6b21\u8bf7\u6c42\u91cd\u65b0\u63e1\u624b\u3002<br \/>\n\u7ed3\u6784\u5316\u5e76\u53d1&#xff1a;asyncio.TaskGroup&#xff08;3.11&#043;&#xff09;\u4fdd\u8bc1\u5b50\u4efb\u52a1\u8981\u4e48\u5168\u90e8\u5b8c\u6210\u3001\u8981\u4e48\u5168\u90e8\u53d6\u6d88&#xff0c;\u5931\u8d25\u65f6\u81ea\u52a8\u53d6\u6d88\u5144\u5f1f\u4efb\u52a1&#xff0c;\u4e0d\u7559\u4e0b\u5b64\u513f\u534f\u7a0b\u3002<\/p>\n<p>\u6838\u5fc3\u5185\u5bb9<br \/>\n\u4ee5\u4e0b\u4ee3\u7801\u4e3a\u6700\u5c0f\u5316\u6f14\u793a\u5b9e\u73b0&#xff0c;\u751f\u4ea7\u73af\u5883\u9700\u63a5\u5165\u771f\u5b9e\u7684\u8ba4\u8bc1\u7ec4\u4ef6\u3001Redis \u79df\u7ea6\u4e0e Prometheus \u6307\u6807\u5bfc\u51fa\u3002<\/p>\n<p>\u5f02\u6b65\u6247\u51fa &#043; \u8fde\u63a5\u6c60 &#043; \u5e76\u53d1\u4e0a\u9650<br \/>\npython<br \/>\nimport asyncio<br \/>\nfrom contextlib import asynccontextmanager<\/p>\n<p>import httpx<br \/>\nfrom fastapi import FastAPI<\/p>\n<p>LLM_URL &#061; \u201chttp:\/\/127.0.0.1:8000\/v1\/chat\/completions\u201d<br \/>\nMAX_CONCURRENT &#061; 64<\/p>\n<p>client: httpx.AsyncClient | None &#061; None<br \/>\nsem &#061; asyncio.Semaphore(MAX_CONCURRENT)<\/p>\n<p>&#064;asynccontextmanager<br \/>\nasync def lifespan(app: FastAPI):<br \/>\nglobal client<br \/>\nlimits &#061; httpx.Limits(<br \/>\nmax_connections&#061;200,<br \/>\nmax_keepalive_connections&#061;50,<br \/>\nkeepalive_expiry&#061;120.0,<br \/>\n)<br \/>\nclient &#061; httpx.AsyncClient(<br \/>\nlimits&#061;limits,<br \/>\ntimeout&#061;httpx.Timeout(60.0, connect&#061;5.0),<br \/>\n)<br \/>\nyield<br \/>\nawait client.aclose()<\/p>\n<p>app &#061; FastAPI(lifespan&#061;lifespan)<\/p>\n<p>async def call_llm(prompt: str) -&gt; str:<br \/>\nasync with sem:<br \/>\nresp &#061; await client.post(<br \/>\nLLM_URL,<br \/>\njson&#061;{\u201cmodel\u201d: \u201clocal\u201d, \u201cmessages\u201d: [{\u201crole\u201d: \u201cuser\u201d, \u201ccontent\u201d: prompt}]},<br \/>\n)<br \/>\nresp.raise_for_status()<br \/>\nreturn resp.json()[\u201cchoices\u201d][0][\u201cmessage\u201d][\u201ccontent\u201d]<\/p>\n<p>&#064;app.post(\u201c\/v1\/batch\u201d)<br \/>\nasync def batch(requests: list[dict]):<br \/>\nprompts &#061; [r[\u201cprompt\u201d] for r in requests]<br \/>\nresults &#061; await asyncio.gather(<br \/>\n*[call_llm\u00a7 for p in prompts],<br \/>\nreturn_exceptions&#061;True,<br \/>\n)<br \/>\nreturn {<br \/>\n\u201cresults\u201d: [<br \/>\nr if not isinstance(r, Exception) else {\u201cerror\u201d: str\u00ae}<br \/>\nfor r in results<br \/>\n]<br \/>\n}<br \/>\n\u8fd0\u884c\u547d\u4ee4&#xff1a;<\/p>\n<p>bash<br \/>\npip install \u201cfastapi&gt;&#061;0.115\u201d \u201cuvicorn&gt;&#061;0.30\u201d \u201chttpx&gt;&#061;0.27\u201d<br \/>\nuvicorn main:app &#8211;host 0.0.0.0 &#8211;port 8000<br \/>\n\u9884\u671f\u8f93\u51fa&#xff08;POST \/v1\/batch \u4f20\u5165 10 \u6761 prompt&#xff09;&#xff1a;10 \u4e2a call_llm \u534f\u7a0b\u5e76\u53d1\u63a8\u8fdb&#xff0c;\u53d7 sem \u7ea6\u675f\u540c\u65f6\u6700\u591a 64 \u4e2a\u8fdb\u5165\u4e0b\u6e38&#xff1b;httpx.AsyncClient \u5728 lifespan \u4e2d\u5355\u4f8b\u521b\u5efa&#xff0c;\u6240\u6709\u8bf7\u6c42\u590d\u7528\u540c\u4e00\u8fde\u63a5\u6c60\u3002<\/p>\n<p>\u56db\u5c42\u74f6\u9888\u4e0e\u5bf9\u5e94\u6539\u9020<br \/>\n\u74f6\u9888\u5c42\u8868\u73b0\u6539\u9020\u624b\u6bb5\u6548\u679c\u4f9d\u636e<br \/>\nIO \u7b49\u5f85\u540c\u6b65 requests \u5360\u7ebf\u7a0b\u7b49\u7f51\u7edc&#xff0c;\u7ebf\u7a0b\u6570\u5373\u5e76\u53d1\u4e0a\u9650\u66ff\u6362\u4e3a httpx.AsyncClient \u6216 aiohttp.ClientSession&#xff0c;await \u671f\u95f4\u8ba9\u51fa\u4e8b\u4ef6\u5faa\u73af\u5355\u8fdb\u7a0b uvicorn \u4ece 47 QPS \u63d0\u5347\u5230 210 QPS<br \/>\n\u540c\u6b65\u963b\u585e\u540c\u6b65 SDK \u6216 CPU \u5bc6\u96c6\u4ee3\u7801\u5361\u4f4f\u4e8b\u4ef6\u5faa\u73af&#xff0c;\u5e76\u53d1\u8bf7\u6c42\u5168\u90e8\u6392\u961fasyncio.to_thread \u6216 loop.run_in_executor \u653e\u5165\u7ebf\u7a0b\u6c60to_thread \u89e3\u9664\u963b\u585e\u4f46\u4e0d\u52a0\u901f\u4efb\u52a1\u672c\u8eab&#xff1b;\u9ed8\u8ba4\u7ebf\u7a0b\u6c60 min(32, cpu&#043;4) \u9700\u6309\u8d1f\u8f7d\u81ea\u5b9a\u4e49<br \/>\n\u8fde\u63a5\u5f00\u9500\u6bcf\u6b21\u8c03\u7528\u65b0\u5efa AsyncClient&#xff0c;\u91cd\u590d TCP &#043; TLS \u63e1\u624b&#xff0c;\u5e76\u53d1\u4e0b\u79ef\u7d2f TIME_WAITlifespan \u4e2d\u5355\u4f8b\u521b\u5efa\u5ba2\u6237\u7aef&#xff0c;\u663e\u5f0f httpx.Limits \u5e76\u62c9\u957f keepalive_expiry\u8fde\u63a5\u5f00\u9500\u7ea6 50\u2013100ms\/\u6b21&#xff0c;500ms \u6a21\u578b\u5ef6\u8fdf\u4e0b\u5360\u6bd4\u663e\u8457<br \/>\n\u65e0\u754c\u5e76\u53d1\u4e0b\u6e38 LLM \u88ab\u77ac\u65f6\u8bf7\u6c42\u6253\u6ee1&#xff0c;\u6392\u961f\u5ef6\u8fdf\u4f20\u5bfc\u56de\u63a5\u53e3asyncio.Semaphore \u5355\u8fdb\u7a0b\u9650\u6d41&#xff1b;\u591a worker \u6362 fastapi-stream-lease\u4f20\u7edf\u9650\u6d41\u5668\u5bf9\u957f\u8fde\u63a5\u5931\u6548&#xff0c;\u9700\u6309\u201c\u5f53\u524d\u6d3b\u8dc3\u6d41\u6570\u201d\u800c\u975e\u8bf7\u6c42\u9891\u6b21\u9650\u5236<br \/>\n\u907f\u5751\u6e05\u5355<br \/>\nasyncio.to_thread \u4e0d\u52a0\u901f CPU \u5bc6\u96c6\u4efb\u52a1&#xff1a;\u7ebf\u7a0b\u53d7 GIL \u7ea6\u675f&#xff0c;\u7eaf Python \u8ba1\u7b97\u653e\u7ebf\u7a0b\u6c60\u4e0d\u4f1a\u53d8\u5feb&#xff0c;\u5e94\u8d70\u8fdb\u7a0b\u6c60\u6216\u72ec\u7acb worker \u670d\u52a1\u3002<\/p>\n<p>run_in_executor \u4e0d\u4f20\u9012 contextvars&#xff1a;\u8bf7\u6c42\u7ea7\u8ffd\u8e2a ID \u5728\u7ebf\u7a0b\u6c60\u5185\u4e22\u5931&#xff1b;\u9700\u8981\u4e0a\u4e0b\u6587\u4f20\u64ad\u65f6\u4f7f\u7528 to_thread&#xff0c;\u5b83\u4f1a\u628a\u5f53\u524d\u4e0a\u4e0b\u6587\u7684 contextvars \u62f7\u8d1d\u5230\u7ebf\u7a0b\u3002<\/p>\n<p>asyncio.gather \u9ed8\u8ba4\u4e0d\u53d6\u6d88\u5144\u5f1f\u4efb\u52a1&#xff1a;\u4e00\u4e2a\u534f\u7a0b\u629b\u5f02\u5e38\u540e&#xff0c;\u5176\u4f59\u534f\u7a0b\u7ee7\u7eed\u5728\u540e\u53f0\u8fd0\u884c&#xff0c;\u5f62\u6210\u5b64\u513f\u4efb\u52a1&#xff1b;\u9700\u8981\u4e25\u683c\u53d6\u6d88\u8bed\u4e49\u65f6\u4f7f\u7528 asyncio.TaskGroup\u3002<\/p>\n<p>\u9ed8\u8ba4 httpx \u8fde\u63a5\u6c60\u4f1a\u9971\u548c&#xff1a;\u5355\u79df\u6237\u5e76\u53d1 160 \u65f6&#xff0c;\u9ed8\u8ba4 100 \u6700\u5927\u8fde\u63a5\u6570\u6392\u961f&#xff0c;\u5176\u4ed6\u79df\u6237\u7684 p95 \u88ab\u62c9\u9ad8 8 \u500d&#xff1b;max_connections \u5e94\u8986\u76d6\u6700\u574f\u6247\u51fa\u3002<\/p>\n<p>asyncio.Semaphore \u4e0d\u8de8 worker&#xff1a;\u6bcf\u4e2a Uvicorn \u8fdb\u7a0b\u72ec\u7acb\u8ba1\u6570&#xff0c;\u603b\u5e76\u53d1\u4e0a\u9650\u6309 worker \u6570\u6210\u500d\u653e\u5927&#xff1b;\u591a\u8fdb\u7a0b\u90e8\u7f72\u9700 Redis \u79df\u7ea6\u3002<\/p>\n<p>\u5e38\u89c1\u95ee\u9898\u4e0e\u6392\u9519<br \/>\n\u73b0\u8c61&#xff1a;\u538b\u6d4b QPS \u5361\u5728\u51e0\u5341&#xff0c;CPU \u5229\u7528\u7387\u5f88\u4f4e\u3002<br \/>\n\u2192 \u539f\u56e0&#xff1a;\u540c\u6b65 requests \u6216\u963b\u585e SDK \u8c03\u7528\u72ec\u5360\u7ebf\u7a0b&#xff0c;\u4e8b\u4ef6\u5faa\u73af\u65e0\u6cd5\u8c03\u5ea6\u5176\u4ed6\u534f\u7a0b\u3002<br \/>\n\u2192 \u89e3\u51b3&#xff1a;\u66ff\u6362\u4e3a httpx.AsyncClient \u7b49\u5f02\u6b65\u5ba2\u6237\u7aef&#xff1b;\u65e0\u6cd5\u66ff\u6362\u7684\u540c\u6b65\u8c03\u7528\u7528 asyncio.to_thread \u9694\u79bb\u3002<\/p>\n<p>\u73b0\u8c61&#xff1a;\u5355\u4e2a\u8bf7\u6c42\u53d8\u6162\u65f6&#xff0c;\u6240\u6709\u5e76\u53d1\u8bf7\u6c42\u4e00\u8d77\u53d8\u6162\u3002<br \/>\n\u2192 \u539f\u56e0&#xff1a;async def \u8def\u7531\u4e2d\u5b58\u5728\u672a await \u7684\u540c\u6b65\u963b\u585e\u8c03\u7528&#xff0c;\u4e8b\u4ef6\u5faa\u73af\u88ab\u72ec\u5360\u3002<br \/>\n\u2192 \u89e3\u51b3&#xff1a;\u7528 await asyncio.to_thread(sync_func, \u2026) \u5305\u88c5\u963b\u585e\u51fd\u6570&#xff0c;\u786e\u4fdd\u534f\u7a0b\u5728\u7b49\u5f85\u671f\u95f4\u8ba9\u51fa\u63a7\u5236\u6743\u3002<\/p>\n<p>\u73b0\u8c61&#xff1a;\u5e76\u53d1\u5347\u9ad8\u540e\u51fa\u73b0 httpx.PoolTimeout \u6216\u8bf7\u6c42\u6392\u961f\u5ef6\u8fdf\u98d9\u5347\u3002<br \/>\n\u2192 \u539f\u56e0&#xff1a;httpx.Limits.max_connections \u5c0f\u4e8e\u5b9e\u9645\u5e76\u53d1\u6247\u51fa&#xff0c;\u540e\u7eed\u8bf7\u6c42\u5728\u8fde\u63a5\u6c60\u5185\u6392\u961f\u3002<br \/>\n\u2192 \u89e3\u51b3&#xff1a;\u6309\u5355\u8fdb\u7a0b\u6700\u574f\u5e76\u53d1\u6570\u8bbe\u7f6e max_connections&#xff0c;\u5e76\u540c\u6b65\u8c03\u6574 max_keepalive_connections \u8986\u76d6\u7a33\u6001\u5e76\u53d1\u3002<\/p>\n<p>\u73b0\u8c61&#xff1a;asyncio.gather \u4e2d\u4e00\u4e2a\u4efb\u52a1\u5931\u8d25\u540e&#xff0c;\u5176\u4f59\u4efb\u52a1\u4ecd\u5728\u540e\u53f0\u8fd0\u884c\u3002<br \/>\n\u2192 \u539f\u56e0&#xff1a;gather \u9ed8\u8ba4\u5728\u9996\u4e2a\u5f02\u5e38\u65f6\u5411\u8c03\u7528\u8005\u4f20\u64ad&#xff0c;\u4f46\u4e0d\u53d6\u6d88\u5144\u5f1f\u4efb\u52a1&#xff0c;\u5b64\u513f\u534f\u7a0b\u7ee7\u7eed\u6d88\u8017\u8d44\u6e90\u3002<br \/>\n\u2192 \u89e3\u51b3&#xff1a;\u6539\u7528 async with asyncio.TaskGroup() as tg \u521b\u5efa\u4efb\u52a1&#xff0c;\u5931\u8d25\u65f6\u81ea\u52a8\u53d6\u6d88\u7ec4\u5185\u5176\u4f59\u4efb\u52a1\u5e76\u629b\u51fa ExceptionGroup\u3002<\/p>\n<p>\u73b0\u8c61&#xff1a;asyncio.to_thread \u9ad8\u5e76\u53d1\u4e0b\u62a5 RuntimeError: cannot schedule new futures after shutdown\u3002<br \/>\n\u2192 \u539f\u56e0&#xff1a;\u9ed8\u8ba4\u7ebf\u7a0b\u6c60\u5bb9\u91cf\u8017\u5c3d&#xff0c;\u6216\u4e8b\u4ef6\u5faa\u73af\u5173\u95ed\u65f6\u4ecd\u6709\u7ebf\u7a0b\u4efb\u52a1\u5728\u8fd0\u884c\u3002<br \/>\n\u2192 \u89e3\u51b3&#xff1a;\u81ea\u5b9a\u4e49 ThreadPoolExecutor \u5e76\u663e\u5f0f\u7ba1\u7406\u751f\u547d\u5468\u671f&#xff0c;\u5728 lifespan \u5173\u95ed\u9636\u6bb5 shutdown(wait&#061;True)\u3002<\/p>\n<p>\u4f18\u5316\u5efa\u8bae\u4e0e\u8fb9\u754c<br \/>\n\u5f02\u6b65\u6539\u9020\u7684\u4f18\u5148\u7ea7\u5e94\u4e25\u683c\u6309\u74f6\u9888\u6d4b\u91cf\u7ed3\u679c\u6392\u5217&#xff1a;\u5148\u6d88\u9664 IO \u7b49\u5f85&#xff08;\u5f02\u6b65\u5ba2\u6237\u7aef&#xff09;&#xff0c;\u518d\u9694\u79bb\u65e0\u6cd5\u6539\u5199\u7684\u540c\u6b65\u963b\u585e&#xff08;to_thread&#xff09;&#xff0c;\u7136\u540e\u590d\u7528\u8fde\u63a5&#xff08;\u5355\u4f8b\u5ba2\u6237\u7aef &#043; \u8fde\u63a5\u6c60&#xff09;&#xff0c;\u6700\u540e\u52a0\u4e0a\u5e76\u53d1\u4e0a\u9650\u4fdd\u62a4\u4e0b\u6e38\u3002\u8fde\u63a5\u6c60\u590d\u7528\u4e0e\u5e76\u53d1\u9650\u6d41\u662f\u76f8\u4e92\u72ec\u7acb\u7684\u4e24\u5c42&#xff1a;\u8fde\u63a5\u6c60\u7ea6\u675f\u201c\u80fd\u540c\u65f6\u6253\u5f00\u591a\u5c11\u8fde\u63a5\u201d&#xff0c;\u4fe1\u53f7\u91cf\u7ea6\u675f\u201c\u80fd\u540c\u65f6\u53d1\u8d77\u591a\u5c11\u8bf7\u6c42\u201d&#xff0c;\u540e\u8005\u5e94\u5c0f\u4e8e\u7b49\u4e8e\u524d\u8005&#xff0c;\u5426\u5219\u8bf7\u6c42\u5728\u8fde\u63a5\u6c60\u5185\u90e8\u6392\u961f&#xff0c;\u9650\u6d41\u5931\u6548\u3002<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff1a;I\/O \u5bc6\u96c6\u578b AI \u63a5\u53e3&#xff08;LLM API \u8c03\u7528\u3001\u5411\u91cf\u68c0\u7d22\u3001\u5916\u90e8\u5de5\u5177\u8c03\u7528&#xff09;\u3001\u9700\u8981\u5e76\u53d1\u6247\u51fa\u7684\u6279\u5904\u7406\u7aef\u70b9\u3002\u5c40\u9650\u6027&#xff1a;\u5f02\u6b65\u4e0d\u52a0\u901f CPU \u5bc6\u96c6\u63a8\u7406&#xff1b;to_thread \u53d7 GIL \u548c\u7ebf\u7a0b\u6c60\u5bb9\u91cf\u7ea6\u675f&#xff1b;\u5355\u8fdb\u7a0b\u4fe1\u53f7\u91cf\u4e0d\u8de8 worker&#xff1b;TaskGroup \u5728\u90e8\u5206\u573a\u666f\u4e0b\u6bd4 gather \u7565\u6162&#xff0c;\u6362\u6765\u7684\u662f\u53ef\u9884\u6d4b\u7684\u53d6\u6d88\u4e0e\u6e05\u7406\u884c\u4e3a\u3002<\/p>\n<p>\u6c42\u804c\u4e0e\u9762\u8bd5\u5173\u8054<\/p>\n<li>\n<p>\u540c\u6b65 requests \u8c03\u7528 LLM \u65f6&#xff0c;QPS \u7684\u7406\u8bba\u4e0a\u9650\u7531\u4ec0\u4e48\u51b3\u5b9a&#xff1f;<br \/>\n\u601d\u8def&#xff1a;\u5e76\u53d1\u7ebf\u7a0b\u6570\u9664\u4ee5\u5355\u6b21\u8c03\u7528\u5e73\u5747\u5ef6\u8fdf\u3002Gunicorn 32 \u5e76\u53d1\u3001680ms \u5ef6\u8fdf\u5bf9\u5e94 47 QPS&#xff0c;\u4e0e\u5b9e\u6d4b\u543b\u5408&#xff1b;\u74f6\u9888\u4e0d\u5728 CPU&#xff0c;\u5728\u7ebf\u7a0b\u7b49\u5f85 IO\u3002<\/p>\n<\/li>\n<li>\n<p>asyncio.to_thread \u548c loop.run_in_executor \u7684\u6838\u5fc3\u5dee\u5f02\u662f\u4ec0\u4e48&#xff1f;<br \/>\n\u601d\u8def&#xff1a;to_thread&#xff08;3.9&#043;&#xff09;\u5c01\u88c5\u9ed8\u8ba4\u7ebf\u7a0b\u6c60\u5e76\u4f20\u9012 contextvars&#xff1b;run_in_executor \u66f4\u5e95\u5c42&#xff0c;\u53ef\u6307\u5b9a\u81ea\u5b9a\u4e49 Executor&#xff0c;\u4f46\u4e0d\u4f20\u9012\u4e0a\u4e0b\u6587\u3002\u9ed8\u8ba4\u7ebf\u7a0b\u6c60\u5927\u5c0f\u5747\u4e3a min(32, cpu&#043;4)&#xff0c;\u9ad8\u5e76\u53d1\u9700\u81ea\u5b9a\u4e49\u3002<\/p>\n<\/li>\n<li>\n<p>asyncio.gather \u5728\u5f02\u5e38\u573a\u666f\u4e0b\u6709\u4ec0\u4e48\u98ce\u9669&#xff1f;TaskGroup \u5982\u4f55\u4fee\u590d&#xff1f;<br \/>\n\u601d\u8def&#xff1a;gather \u9ed8\u8ba4\u4e0d\u53d6\u6d88\u5144\u5f1f\u4efb\u52a1&#xff0c;\u9996\u4e2a\u5f02\u5e38\u4f20\u64ad\u540e\u5176\u4f59\u534f\u7a0b\u7ee7\u7eed\u8fd0\u884c&#xff1b;TaskGroup&#xff08;3.11&#043;&#xff09;\u4fdd\u8bc1\u9000\u51fa async with \u5757\u65f6\u6240\u6709\u5b50\u4efb\u52a1\u8981\u4e48\u5b8c\u6210\u8981\u4e48\u88ab\u53d6\u6d88&#xff0c;\u5931\u8d25\u81ea\u52a8\u53d6\u6d88\u5144\u5f1f\u4efb\u52a1\u5e76\u805a\u5408\u4e3a ExceptionGroup\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4ec0\u4e48\u6bcf\u6b21\u8bf7\u6c42\u65b0\u5efa httpx.AsyncClient \u4f1a\u62d6\u6162 AI \u63a5\u53e3&#xff1f;<br \/>\n\u601d\u8def&#xff1a;\u65b0\u5efa\u5ba2\u6237\u7aef\u610f\u5473\u7740\u65b0\u5efa\u8fde\u63a5\u6c60&#xff0c;\u6bcf\u6b21\u8c03\u7528\u627f\u62c5 TCP &#043; TLS \u63e1\u624b\u5f00\u9500&#xff08;\u7ea6 50\u2013100ms&#xff09;&#xff0c;\u5e76\u53d1\u4e0b\u79ef\u7d2f TIME_WAIT\u3002\u5355\u4f8b\u5ba2\u6237\u7aef &#043; \u663e\u5f0f Limits &#043; \u62c9\u957f keepalive_expiry \u53ef\u590d\u7528\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>AI \u63a5\u53e3\u7684\u5e76\u53d1\u9650\u5236\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u7528\u4f20\u7edf\u8bf7\u6c42\u8ba1\u6570\u9650\u6d41\u5668&#xff1f;<br \/>\n\u601d\u8def&#xff1a;\u6d41\u5f0f LLM \u8bf7\u6c42\u53ef\u4fdd\u6301\u8fde\u63a5 30 \u79d2\u4ee5\u4e0a&#xff0c;\u4f20\u7edf RPM \u9650\u6d41\u5668\u5c06\u5176\u8ba1\u4e3a\u201c1 \u6b21\u8bf7\u6c42\u201d&#xff0c;\u65e0\u6cd5\u611f\u77e5\u8fde\u63a5\u6301\u7eed\u5360\u7528&#xff1b;\u9700\u8981\u6309\u201c\u5f53\u524d\u6d3b\u8dc3\u6d41\u6570\u91cf\u201d\u505a\u79df\u7ea6\u5f0f\u9650\u5236&#xff0c;\u5e76\u5728\u5ba2\u6237\u7aef\u65ad\u5f00\u65f6\u7acb\u5373\u91ca\u653e\u3002<\/p>\n<\/li>\n<li>\n<p>asyncio.Semaphore \u591a worker \u90e8\u7f72\u540e\u4e3a\u4ec0\u4e48\u5931\u6548&#xff1f;\u66ff\u4ee3\u65b9\u6848\u662f\u4ec0\u4e48&#xff1f;<br \/>\n\u601d\u8def&#xff1a;\u4fe1\u53f7\u91cf\u662f\u8fdb\u7a0b\u5185\u72b6\u6001&#xff0c;\u6bcf\u4e2a Uvicorn worker \u72ec\u7acb\u8ba1\u6570&#xff0c;\u603b\u4e0a\u9650\u6309 worker \u6570\u653e\u5927\u3002\u66ff\u4ee3\u65b9\u6848\u662f Redis \u539f\u5b50 Lua \u811a\u672c\u5b9e\u73b0\u7684\u5206\u5e03\u5f0f\u79df\u7ea6&#xff0c;\u5728\u8fdb\u7a0b\u5916\u7edf\u4e00\u7ea6\u675f\u5e76\u53d1\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f02\u6b65\u6539\u9020\u540e QPS \u63d0\u5347\u4f46 P99 \u4ecd\u7136\u5f88\u9ad8&#xff0c;\u53ef\u80fd\u539f\u56e0\u662f\u4ec0\u4e48&#xff1f;<br \/>\n\u601d\u8def&#xff1a;\u5f02\u6b65\u6d88\u9664\u4e86\u7ebf\u7a0b\u7b49\u5f85&#xff0c;\u4f46\u4e0b\u6e38 LLM \u670d\u52a1\u672c\u8eab\u6709\u6392\u961f\u5bb9\u91cf\u4e0a\u9650&#xff1b;\u5f02\u6b65\u5ba2\u6237\u7aef\u628a\u8bf7\u6c42\u66f4\u5feb\u5730\u63a8\u7ed9\u4e0b\u6e38&#xff0c;\u5ef6\u8fdf\u4ece\u63a5\u53e3\u5c42\u8f6c\u79fb\u5230\u4e0b\u6e38\u961f\u5217\u3002\u9700\u8981\u914d\u5408\u4fe1\u53f7\u91cf\u6216\u5fae\u6279\u5904\u7406\u7ea6\u675f\u4e0b\u6e38\u538b\u529b\u3002<\/p>\n<\/li>\n<li>\n<p>TaskGroup \u6bd4 gather \u6162\u4e00\u70b9\u662f\u6027\u80fd\u95ee\u9898\u5417&#xff1f;<br \/>\n\u601d\u8def&#xff1a;\u4e0d\u662f\u3002TaskGroup \u7684\u989d\u5916\u5f00\u9500\u6765\u81ea\u5f3a\u5236\u7b49\u5f85\u4efb\u52a1\u6e05\u7406\u548c\u53d6\u6d88\u4f20\u64ad&#xff0c;\u8fd9\u662f gather \u4e0d\u505a\u7684\u4e8b&#xff1b;\u6362\u6765\u7684\u662f\u53ef\u9884\u6d4b\u3001\u53ef\u8c03\u8bd5\u7684\u5e76\u53d1\u884c\u4e3a&#xff0c;\u751f\u4ea7\u73af\u5883\u4f18\u5148\u9009\u62e9\u3002<\/p>\n<\/li>\n<p>\u603b\u7ed3<br \/>\nAI \u63a5\u53e3\u5e76\u53d1\u74f6\u9888\u6309 IO \u7b49\u5f85\u3001\u540c\u6b65\u963b\u585e\u3001\u8fde\u63a5\u5f00\u9500\u3001\u65e0\u754c\u5e76\u53d1\u56db\u5c42\u4f9d\u6b21\u51fa\u73b0&#xff0c;\u6539\u9020\u987a\u5e8f\u5e94\u4e0e\u74f6\u9888\u6d4b\u91cf\u7ed3\u679c\u4e00\u81f4&#xff0c;\u800c\u975e\u4e00\u6b21\u6027\u5806\u53e0\u6240\u6709\u5f02\u6b65\u624b\u6bb5\u3002<\/p>\n<p>\u540c\u6b65 requests \u7684 47 QPS \u662f\u7ebf\u7a0b\u6570\u9664\u4ee5\u5ef6\u8fdf\u7684\u76f4\u63a5\u7ed3\u679c&#xff1b;\u6362\u6210\u5f02\u6b65\u5ba2\u6237\u7aef\u540e\u5355\u8fdb\u7a0b\u5373\u53ef\u8fdb\u5165 200 QPS \u91cf\u7ea7&#xff0c;\u5269\u4f59\u74f6\u9888\u8f6c\u79fb\u5230\u4e0b\u6e38\u548c\u8fde\u63a5\u5c42\u3002<\/p>\n<p>httpx.AsyncClient \u5e94\u5728 lifespan \u4e2d\u5355\u4f8b\u521b\u5efa&#xff0c;\u663e\u5f0f\u914d\u7f6e max_connections \u4e0e keepalive_expiry&#xff0c;\u907f\u514d\u6bcf\u6b21\u8bf7\u6c42\u91cd\u5efa\u8fde\u63a5\u6c60\u3002<\/p>\n<p>asyncio.to_thread \u662f\u963b\u585e\u9694\u79bb\u624b\u6bb5\u800c\u975e\u52a0\u901f\u624b\u6bb5&#xff0c;\u9ed8\u8ba4\u7ebf\u7a0b\u6c60 min(32, cpu&#043;4) \u4e0d\u968f\u8d1f\u8f7d\u4f38\u7f29&#xff0c;\u9ad8\u5e76\u53d1\u9700\u81ea\u5b9a\u4e49 Executor\u3002<\/p>\n<p>asyncio.gather \u9ed8\u8ba4\u4e0d\u53d6\u6d88\u5144\u5f1f\u4efb\u52a1&#xff0c;asyncio.TaskGroup \u63d0\u4f9b\u7ed3\u6784\u5316\u5e76\u53d1\u4fdd\u8bc1&#xff1b;asyncio.Semaphore \u4ec5\u9650\u5355\u8fdb\u7a0b&#xff0c;\u591a worker \u90e8\u7f72\u5fc5\u987b\u8fc1\u79fb\u5230 Redis \u79df\u7ea6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content<\/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":[14214,14213,3500,72],"topic":[],"class_list":["post-123996","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai-","tag-httpx-","tag-asyncio","tag-fastapi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b - \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\/123996.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/123996.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-08T08:56:46+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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/123996.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/123996.html\",\"name\":\"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-11-08T08:56:46+00:00\",\"dateModified\":\"2026-11-08T08:56:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/123996.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/123996.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/123996.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b\"}]},{\"@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":"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b - \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\/123996.html","og_locale":"zh_CN","og_type":"article","og_title":"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content","og_url":"https:\/\/www.wsisp.com\/helps\/123996.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-11-08T08:56:46+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/123996.html","url":"https:\/\/www.wsisp.com\/helps\/123996.html","name":"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-11-08T08:56:46+00:00","dateModified":"2026-11-08T08:56:46+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/123996.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/123996.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/123996.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python \u5f02\u6b65\u5f00\u53d1\uff1a\u63d0\u5347 AI \u63a5\u53e3\u5e76\u53d1\u5904\u7406\u80fd\u529b"}]},{"@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\/123996","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=123996"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/123996\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=123996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=123996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=123996"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=123996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}