{"id":81598,"date":"2026-07-25T02:59:27","date_gmt":"2026-07-24T18:59:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/81598.html"},"modified":"2026-07-25T02:59:27","modified_gmt":"2026-07-24T18:59:27","slug":"python-%e5%bc%82%e6%ad%a5%e7%bc%96%e7%a8%8b%ef%bc%9a%e4%bb%8e%e5%8d%8f%e7%a8%8b%e8%b0%83%e5%ba%a6%e5%88%b0%e9%ab%98%e5%b9%b6%e5%8f%91%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/81598.html","title":{"rendered":"Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18"},"content":{"rendered":"<h2>Python \u5f02\u6b65\u7f16\u7a0b&#xff1a;\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18<\/h2>\n<h3>\u4e00\u3001\u540c\u6b65\u963b\u585e\u7684\u4ee3\u4ef7<\/h3>\n<p>\u4e00\u4e2a\u5178\u578b\u7684 Python Web \u670d\u52a1\u5728\u5904\u7406\u6570\u636e\u5e93\u67e5\u8be2\u65f6&#xff0c;\u7ebf\u7a0b\u4f1a\u5728 I\/O \u7b49\u5f85\u671f\u95f4\u88ab\u5b8c\u5168\u5360\u7528\u3002\u5e76\u53d1\u8bf7\u6c42\u8fbe\u5230 200 \u65f6&#xff0c;\u7ebf\u7a0b\u6c60\u8017\u5c3d&#xff0c;\u65b0\u8bf7\u6c42\u6392\u961f\u7b49\u5f85&#xff0c;\u54cd\u5e94\u65f6\u95f4\u4ece 50ms \u98d9\u5347\u5230 3 \u79d2\u4ee5\u4e0a\u3002<\/p>\n<p>\u540c\u6b65\u4ee3\u7801\u4e2d\u7684\u6bcf\u4e00\u6b21 requests.get() \u6216 db.execute()&#xff0c;\u90fd\u5728\u9690\u5f0f\u5730\u5236\u9020\u4e00\u4e2a\u963b\u585e\u70b9\u3002\u4f4e\u5e76\u53d1\u65f6\u8fd9\u4e9b\u963b\u585e\u70b9\u6ca1\u6709\u5b58\u5728\u611f&#xff0c;\u6d41\u91cf\u7ffb\u500d\u540e&#xff0c;\u7ebf\u7a0b\u6c60\u6ee1\u4e86&#xff0c;\u961f\u5217\u6ee1\u4e86&#xff0c;\u670d\u52a1\u7194\u65ad\u3002<\/p>\n<p>\u5f02\u6b65\u7f16\u7a0b\u7684\u4ef7\u503c\u4e0d\u662f&#034;\u66f4\u5feb&#034;&#xff0c;\u800c\u662f\u5728 I\/O \u7b49\u5f85\u671f\u95f4\u91ca\u653e\u6267\u884c\u8d44\u6e90\u3002\u540c\u4e00\u4e2a\u7ebf\u7a0b\u5728\u7b49\u5f85\u6570\u636e\u5e93\u54cd\u5e94\u7684\u95f4\u9699\u53ef\u4ee5\u53bb\u5904\u7406\u5176\u4ed6\u8bf7\u6c42\u3002<\/p>\n<h3>\u4e8c\u3001\u534f\u7a0b\u8c03\u5ea6\u673a\u5236<\/h3>\n<p>Python \u5f02\u6b65\u7f16\u7a0b\u7684\u5e95\u5c42\u5f15\u64ce\u662f\u4e8b\u4ef6\u5faa\u73af&#xff08;Event Loop&#xff09;\u3002\u7406\u89e3\u5b83\u7684\u5de5\u4f5c\u673a\u5236&#xff0c;\u662f\u4ece&#034;\u4f1a\u7528 async\/await&#034;\u5230&#034;\u80fd\u8c03\u4f18\u5f02\u6b65\u6027\u80fd&#034;\u7684\u5173\u952e\u3002<\/p>\n<p>sequenceDiagram<br \/>\n    participant Main as \u4e3b\u534f\u7a0b<br \/>\n    participant Loop as \u4e8b\u4ef6\u5faa\u73af<br \/>\n    participant IO as I\/O \u64cd\u4f5c<br \/>\n    participant Ready as \u5c31\u7eea\u961f\u5217<\/p>\n<p>    Main-&gt;&gt;Loop: \u63d0\u4ea4\u534f\u7a0b task_1<br \/>\n    Main-&gt;&gt;Loop: \u63d0\u4ea4\u534f\u7a0b task_2<br \/>\n    Main-&gt;&gt;Loop: \u63d0\u4ea4\u534f\u7a0b task_3<\/p>\n<p>    Note over Loop: \u5f00\u59cb\u8c03\u5ea6\u5faa\u73af<\/p>\n<p>    Loop-&gt;&gt;task_1: \u6062\u590d\u6267\u884c<br \/>\n    task_1-&gt;&gt;Loop: await io_read() \u2192 \u6302\u8d77<br \/>\n    Loop-&gt;&gt;IO: \u6ce8\u518c fd \u53ef\u8bfb\u56de\u8c03<br \/>\n    Loop-&gt;&gt;Ready: task_1 \u52a0\u5165\u7b49\u5f85\u96c6<\/p>\n<p>    Loop-&gt;&gt;task_2: \u6062\u590d\u6267\u884c<br \/>\n    task_2-&gt;&gt;Loop: await io_write() \u2192 \u6302\u8d77<br \/>\n    Loop-&gt;&gt;IO: \u6ce8\u518c fd \u53ef\u5199\u56de\u8c03<br \/>\n    Loop-&gt;&gt;Ready: task_2 \u52a0\u5165\u7b49\u5f85\u96c6<\/p>\n<p>    Loop-&gt;&gt;task_3: \u6062\u590d\u6267\u884c<br \/>\n    task_3-&gt;&gt;Loop: \u8ba1\u7b97\u5b8c\u6210&#xff0c;\u8fd4\u56de\u7ed3\u679c<\/p>\n<p>    IO&#8211;&gt;&gt;Loop: fd \u53ef\u8bfb\u4e8b\u4ef6\u5c31\u7eea<br \/>\n    Loop-&gt;&gt;task_1: \u6062\u590d\u6267\u884c<br \/>\n    task_1-&gt;&gt;Loop: \u8ba1\u7b97\u5b8c\u6210&#xff0c;\u8fd4\u56de\u7ed3\u679c<\/p>\n<p>    IO&#8211;&gt;&gt;Loop: fd \u53ef\u5199\u4e8b\u4ef6\u5c31\u7eea<br \/>\n    Loop-&gt;&gt;task_2: \u6062\u590d\u6267\u884c<br \/>\n    task_2-&gt;&gt;Loop: \u8ba1\u7b97\u5b8c\u6210&#xff0c;\u8fd4\u56de\u7ed3\u679c<\/p>\n<h4>2.1 \u4e8b\u4ef6\u5faa\u73af\u7684\u4e09\u9636\u6bb5\u8c03\u5ea6\u6a21\u578b<\/h4>\n<p>\u4e8b\u4ef6\u5faa\u73af\u7684\u6bcf\u4e00\u6b21\u8fed\u4ee3\u7ecf\u5386\u4e09\u4e2a\u9636\u6bb5&#xff1a;<\/p>\n<p>\u9636\u6bb5\u4e00&#xff1a;\u68c0\u67e5\u5c31\u7eea\u7684 I\/O \u4e8b\u4ef6\u3002\u901a\u8fc7 epoll&#xff08;Linux&#xff09;\u6216 kqueue&#xff08;macOS&#xff09;\u7cfb\u7edf\u8c03\u7528&#xff0c;\u83b7\u53d6\u5df2\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5217\u8868\u3002\u5bf9\u5e94\u7684\u534f\u7a0b\u79fb\u5165\u5c31\u7eea\u961f\u5217\u3002<\/p>\n<p>\u9636\u6bb5\u4e8c&#xff1a;\u6267\u884c\u5c31\u7eea\u961f\u5217\u4e2d\u7684\u534f\u7a0b\u3002\u4f9d\u6b21\u6062\u590d\u5c31\u7eea\u534f\u7a0b\u7684\u6267\u884c&#xff0c;\u76f4\u5230\u534f\u7a0b\u9047\u5230\u4e0b\u4e00\u4e2a await \u6302\u8d77\u70b9\u6216\u6267\u884c\u5b8c\u6bd5\u3002\u6bcf\u4e2a\u534f\u7a0b\u7684\u8fde\u7eed\u6267\u884c\u65f6\u95f4\u4e0d\u5e94\u8fc7\u957f&#xff0c;\u5426\u5219\u5176\u4ed6\u534f\u7a0b\u4f1a\u88ab\u997f\u6b7b\u3002<\/p>\n<p>\u9636\u6bb5\u4e09&#xff1a;\u5904\u7406\u5b9a\u65f6\u5668\u548c\u56de\u8c03\u3002\u6267\u884c\u5230\u671f\u7684 call_later \u56de\u8c03\u548c ensure_future \u6ce8\u518c\u7684\u56de\u8c03\u3002<\/p>\n<h4>2.2 await \u7684\u672c\u8d28<\/h4>\n<p>await \u4e0d\u662f&#034;\u7b49\u5f85\u7ed3\u679c\u8fd4\u56de&#034;&#xff0c;\u800c\u662f\u4e3b\u52a8\u8ba9\u51fa\u63a7\u5236\u6743\u7ed9\u4e8b\u4ef6\u5faa\u73af\u3002\u534f\u7a0b\u6267\u884c\u5230 await coro() \u65f6&#xff0c;\u5c06\u6267\u884c\u72b6\u6001\u6253\u5305\u6210\u751f\u6210\u5668\u5e27&#xff0c;\u6302\u8d77\u5230\u4e8b\u4ef6\u5faa\u73af\u3002\u4e8b\u4ef6\u5faa\u73af\u8c03\u5ea6\u5176\u4ed6\u5c31\u7eea\u534f\u7a0b\u6267\u884c\u3002\u88ab await \u7684\u64cd\u4f5c\u5b8c\u6210\u540e&#xff0c;\u4e8b\u4ef6\u5faa\u73af\u6062\u590d\u8be5\u534f\u7a0b&#xff0c;\u4ece\u6302\u8d77\u70b9\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p>\u8fd9\u610f\u5473\u7740&#xff1a;\u5982\u679c\u5728\u534f\u7a0b\u4e2d\u6267\u884c CPU \u5bc6\u96c6\u578b\u540c\u6b65\u8ba1\u7b97&#xff08;\u6bd4\u5982 1000 \u4e07\u6b21\u7684\u5faa\u73af&#xff09;&#xff0c;\u8fd9\u4e2a\u534f\u7a0b\u5728\u8ba1\u7b97\u5b8c\u6210\u524d\u4e0d\u4f1a\u8ba9\u51fa\u63a7\u5236\u6743&#xff0c;\u4e8b\u4ef6\u5faa\u73af\u88ab\u963b\u585e&#xff0c;\u6240\u6709\u5176\u4ed6\u534f\u7a0b\u90fd\u88ab\u997f\u6b7b\u3002\u8fd9\u662f Python \u5f02\u6b65\u7f16\u7a0b\u4e2d\u6700\u5e38\u89c1\u7684\u6027\u80fd\u9677\u9631\u3002<\/p>\n<h3>\u4e09\u3001\u5f02\u6b65 HTTP \u5ba2\u6237\u7aef\u4e0e\u8fde\u63a5\u6c60\u8c03\u4f18<\/h3>\n<p>import asyncio<br \/>\nimport time<br \/>\nfrom dataclasses import dataclass, field<br \/>\nfrom typing import Any, Optional<\/p>\n<p>import aiohttp<\/p>\n<p>&#064;dataclass<br \/>\nclass RetryPolicy:<br \/>\n    &#034;&#034;&#034;\u91cd\u8bd5\u7b56\u7565\u2014\u2014\u63a7\u5236\u9000\u907f\u884c\u4e3a\u800c\u975e\u7b80\u5355\u91cd\u8bd5\u6b21\u6570&#034;&#034;&#034;<br \/>\n    max_retries: int &#061; 3<br \/>\n    base_delay: float &#061; 0.5          # \u57fa\u7840\u9000\u907f\u65f6\u95f4&#xff08;\u79d2&#xff09;<br \/>\n    max_delay: float &#061; 8.0           # \u9000\u907f\u4e0a\u9650&#xff0c;\u907f\u514d\u7b49\u5f85\u8fc7\u4e45<br \/>\n    backoff_factor: float &#061; 2.0      # \u6307\u6570\u9000\u907f\u56e0\u5b50<br \/>\n    retryable_statuses: set[int] &#061; field(<br \/>\n        default_factory&#061;lambda: {502, 503, 504}<br \/>\n    )<br \/>\n    # \u53ea\u5bf9\u7f51\u5173\u7c7b\u9519\u8bef\u91cd\u8bd5&#xff0c;4xx \u4e0d\u91cd\u8bd5\u2014\u2014\u5ba2\u6237\u7aef\u9519\u8bef\u91cd\u8bd5\u65e0\u610f\u4e49<\/p>\n<p>class AsyncHTTPClient:<br \/>\n    &#034;&#034;&#034;\u751f\u4ea7\u7ea7\u5f02\u6b65 HTTP \u5ba2\u6237\u7aef\u2014\u2014\u8fde\u63a5\u6c60\u590d\u7528 &#043; \u8d85\u65f6 &#043; \u91cd\u8bd5&#034;&#034;&#034;<\/p>\n<p>    def __init__(<br \/>\n        self,<br \/>\n        pool_size: int &#061; 100,<br \/>\n        per_host_limit: int &#061; 20,<br \/>\n        connect_timeout: float &#061; 5.0,<br \/>\n        read_timeout: float &#061; 30.0,<br \/>\n        retry_policy: Optional[RetryPolicy] &#061; None,<br \/>\n    ):<br \/>\n        self.pool_size &#061; pool_size<br \/>\n        self.per_host_limit &#061; per_host_limit<br \/>\n        self.connect_timeout &#061; connect_timeout<br \/>\n        self.read_timeout &#061; read_timeout<br \/>\n        self.retry_policy &#061; retry_policy or RetryPolicy()<\/p>\n<p>        # \u8fde\u63a5\u6c60\u9650\u5236\u5668&#xff1a;\u63a7\u5236\u5bf9\u540c\u4e00\u4e3b\u673a\u7684\u5e76\u53d1\u8fde\u63a5\u6570<br \/>\n        # \u907f\u514d\u5bf9\u4e0b\u6e38\u670d\u52a1\u9020\u6210\u8fc7\u5927\u538b\u529b<br \/>\n        self._host_semaphores: dict[str, asyncio.Semaphore] &#061; {}<br \/>\n        self._session: Optional[aiohttp.ClientSession] &#061; None<\/p>\n<p>    async def _get_session(self) -&gt; aiohttp.ClientSession:<br \/>\n        &#034;&#034;&#034;\u61d2\u521d\u59cb\u5316 Session\u2014\u2014\u786e\u4fdd\u5728\u4e8b\u4ef6\u5faa\u73af\u5185\u521b\u5efa&#034;&#034;&#034;<br \/>\n        if self._session is None or self._session.closed:<br \/>\n            # TCPConnector \u914d\u7f6e\u8fde\u63a5\u6c60\u53c2\u6570<br \/>\n            connector &#061; aiohttp.TCPConnector(<br \/>\n                limit&#061;self.pool_size,           # \u603b\u8fde\u63a5\u6c60\u5927\u5c0f<br \/>\n                limit_per_host&#061;self.per_host_limit,  # \u5355\u4e3b\u673a\u8fde\u63a5\u4e0a\u9650<br \/>\n                ttl_dns_cache&#061;300,              # DNS \u7f13\u5b58 5 \u5206\u949f&#xff0c;\u51cf\u5c11\u89e3\u6790\u5f00\u9500<br \/>\n                enable_cleanup_closed&#061;True,     # \u81ea\u52a8\u6e05\u7406\u5df2\u5173\u95ed\u8fde\u63a5<br \/>\n            )<br \/>\n            timeout &#061; aiohttp.ClientTimeout(<br \/>\n                sock_connect&#061;self.connect_timeout,<br \/>\n                sock_read&#061;self.read_timeout,<br \/>\n            )<br \/>\n            self._session &#061; aiohttp.ClientSession(<br \/>\n                connector&#061;connector,<br \/>\n                timeout&#061;timeout,<br \/>\n            )<br \/>\n        return self._session<\/p>\n<p>    def _get_host_semaphore(self, host: str) -&gt; asyncio.Semaphore:<br \/>\n        &#034;&#034;&#034;\u4e3a\u6bcf\u4e2a\u4e3b\u673a\u5206\u914d\u72ec\u7acb\u7684\u4fe1\u53f7\u91cf\u2014\u2014\u7ec6\u7c92\u5ea6\u5e76\u53d1\u63a7\u5236&#034;&#034;&#034;<br \/>\n        if host not in self._host_semaphores:<br \/>\n            self._host_semaphores[host] &#061; asyncio.Semaphore(self.per_host_limit)<br \/>\n        return self._host_semaphores[host]<\/p>\n<p>    async def _execute_with_retry(<br \/>\n        self,<br \/>\n        method: str,<br \/>\n        url: str,<br \/>\n        **kwargs: Any,<br \/>\n    ) -&gt; aiohttp.ClientResponse:<br \/>\n        &#034;&#034;&#034;\u5e26\u6307\u6570\u9000\u907f\u7684\u91cd\u8bd5\u6267\u884c\u2014\u2014\u907f\u514d\u5728\u4e0b\u6e38\u6296\u52a8\u65f6\u96ea\u5d29&#034;&#034;&#034;<br \/>\n        policy &#061; self.retry_policy<br \/>\n        last_exception: Optional[Exception] &#061; None<\/p>\n<p>        for attempt in range(policy.max_retries &#043; 1):<br \/>\n            try:<br \/>\n                session &#061; await self._get_session()<br \/>\n                async with session.request(method, url, **kwargs) as resp:<br \/>\n                    if resp.status in policy.retryable_statuses:<br \/>\n                        last_exception &#061; Exception(<br \/>\n                            f&#034;\u53ef\u91cd\u8bd5\u7684 HTTP \u72b6\u6001\u7801: {resp.status}&#034;<br \/>\n                        )<br \/>\n                    else:<br \/>\n                        return resp<br \/>\n            except (aiohttp.ClientError, asyncio.TimeoutError) as exc:<br \/>\n                last_exception &#061; exc<\/p>\n<p>            if attempt &lt; policy.max_retries:<br \/>\n                # \u6307\u6570\u9000\u907f&#xff1a;0.5s \u2192 1s \u2192 2s \u2192 4s \u2192 8s&#xff08;\u4e0a\u9650&#xff09;<br \/>\n                delay &#061; min(<br \/>\n                    policy.base_delay * (policy.backoff_factor ** attempt),<br \/>\n                    policy.max_delay,<br \/>\n                )<br \/>\n                await asyncio.sleep(delay)<\/p>\n<p>        # \u6240\u6709\u91cd\u8bd5\u8017\u5c3d&#xff0c;\u629b\u51fa\u6700\u540e\u4e00\u6b21\u5f02\u5e38<br \/>\n        raise last_exception or Exception(&#034;\u672a\u77e5\u91cd\u8bd5\u5931\u8d25&#034;)<\/p>\n<p>    async def get(self, url: str, **kwargs: Any) -&gt; bytes:<br \/>\n        &#034;&#034;&#034;GET \u8bf7\u6c42\u2014\u2014\u5e26\u4e3b\u673a\u7ea7\u5e76\u53d1\u9650\u5236&#034;&#034;&#034;<br \/>\n        from urllib.parse import urlparse<br \/>\n        host &#061; urlparse(url).netloc<br \/>\n        semaphore &#061; self._get_host_semaphore(host)<\/p>\n<p>        # \u4fe1\u53f7\u91cf\u63a7\u5236\u5bf9\u540c\u4e00\u4e3b\u673a\u7684\u5e76\u53d1\u8bf7\u6c42\u6570<br \/>\n        async with semaphore:<br \/>\n            resp &#061; await self._execute_with_retry(&#034;GET&#034;, url, **kwargs)<br \/>\n            return await resp.read()<\/p>\n<p>    async def close(self):<br \/>\n        &#034;&#034;&#034;\u4f18\u96c5\u5173\u95ed\u2014\u2014\u91ca\u653e\u8fde\u63a5\u6c60\u8d44\u6e90&#034;&#034;&#034;<br \/>\n        if self._session and not self._session.closed:<br \/>\n            await self._session.close()<\/p>\n<p>async def batch_fetch(urls: list[str], concurrency: int &#061; 50) -&gt; dict[str, bytes]:<br \/>\n    &#034;&#034;&#034;\u6279\u91cf\u5e76\u53d1\u8bf7\u6c42\u2014\u2014\u7528\u4fe1\u53f7\u91cf\u63a7\u5236\u5168\u5c40\u5e76\u53d1\u5ea6&#034;&#034;&#034;<br \/>\n    client &#061; AsyncHTTPClient(pool_size&#061;concurrency)<br \/>\n    semaphore &#061; asyncio.Semaphore(concurrency)<br \/>\n    results: dict[str, bytes] &#061; {}<\/p>\n<p>    async def fetch_one(url: str):<br \/>\n        async with semaphore:<br \/>\n            try:<br \/>\n                data &#061; await client.get(url)<br \/>\n                results[url] &#061; data<br \/>\n            except Exception as exc:<br \/>\n                results[url] &#061; f&#034;ERROR: {exc}&#034;.encode()<\/p>\n<p>    try:<br \/>\n        await asyncio.gather(*[fetch_one(url) for url in urls])<br \/>\n    finally:<br \/>\n        await client.close()<\/p>\n<p>    return results<\/p>\n<h4>3.1 \u5173\u952e\u8c03\u4f18\u53c2\u6570<\/h4>\n<p>pool_size vs per_host_limit&#xff1a;\u603b\u8fde\u63a5\u6c60\u5927\u5c0f\u51b3\u5b9a\u5ba2\u6237\u7aef\u7684\u5e76\u53d1\u4e0a\u9650&#xff0c;\u5355\u4e3b\u673a\u9650\u5236\u51b3\u5b9a\u5bf9\u4e0b\u6e38\u7684\u51b2\u51fb\u529b\u5ea6\u3002\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;per_host_limit \u901a\u5e38\u8bbe\u4e3a\u4e0b\u6e38\u670d\u52a1\u627f\u8f7d\u80fd\u529b\u7684 60%-70%&#xff0c;\u7559\u51fa\u4f59\u91cf\u5e94\u5bf9\u7a81\u53d1\u6d41\u91cf\u3002<\/p>\n<p>DNS \u7f13\u5b58&#xff1a;ttl_dns_cache&#061;300 \u5c06 DNS \u89e3\u6790\u7ed3\u679c\u7f13\u5b58 5 \u5206\u949f\u3002\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b&#xff0c;DNS \u89e3\u6790\u53ef\u80fd\u6210\u4e3a\u9690\u85cf\u7684\u74f6\u9888\u2014\u2014\u6bcf\u6b21\u8bf7\u6c42\u90fd\u89e3\u6790\u57df\u540d&#xff0c;\u4e0d\u4ec5\u589e\u52a0\u5ef6\u8fdf&#xff0c;\u8fd8\u53ef\u80fd\u89e6\u53d1 DNS \u670d\u52a1\u7684\u9650\u6d41\u3002<\/p>\n<p>\u4fe1\u53f7\u91cf\u7684\u4e24\u5c42\u63a7\u5236&#xff1a;\u5168\u5c40\u4fe1\u53f7\u91cf\u63a7\u5236\u603b\u5e76\u53d1\u5ea6&#xff0c;\u4e3b\u673a\u7ea7\u4fe1\u53f7\u91cf\u63a7\u5236\u5355\u76ee\u6807\u5e76\u53d1\u5ea6\u3002\u53cc\u5c42\u9650\u6d41\u8bbe\u8ba1\u53ef\u4ee5\u6709\u6548\u9632\u6b62&#034;\u67d0\u4e2a\u6162\u670d\u52a1\u5403\u6389\u6240\u6709\u8fde\u63a5&#034;\u7684\u95ee\u9898\u3002<\/p>\n<h3>\u56db\u3001\u5f02\u6b65\u7f16\u7a0b\u7684\u9677\u9631<\/h3>\n<p>\u5f02\u6b65\u7f16\u7a0b\u5e76\u975e\u4e07\u80fd\u836f&#xff0c;Python \u7684\u5f02\u6b65\u751f\u6001\u5b58\u5728\u51e0\u4e2a\u5bb9\u6613\u88ab\u5ffd\u89c6\u7684\u9677\u9631\u3002<\/p>\n<p>GIL \u4e0e CPU \u5bc6\u96c6\u578b\u4efb\u52a1&#xff1a;Python \u7684 GIL&#xff08;\u5168\u5c40\u89e3\u91ca\u5668\u9501&#xff09;\u4f7f\u5f97\u5f02\u6b65\u534f\u7a0b\u65e0\u6cd5\u5229\u7528\u591a\u6838 CPU\u3002\u534f\u7a0b\u6267\u884c CPU \u5bc6\u96c6\u578b\u8ba1\u7b97\u65f6&#xff0c;GIL \u4e0d\u4f1a\u88ab\u91ca\u653e&#xff0c;\u4e8b\u4ef6\u5faa\u73af\u88ab\u963b\u585e\u3002\u89e3\u51b3\u65b9\u6848\u662f\u5c06 CPU \u5bc6\u96c6\u578b\u4efb\u52a1\u59d4\u6258\u7ed9\u8fdb\u7a0b\u6c60&#xff08;ProcessPoolExecutor&#xff09;&#xff0c;\u901a\u8fc7 loop.run_in_executor \u5728\u5b50\u8fdb\u7a0b\u4e2d\u6267\u884c&#xff0c;\u7ed5\u8fc7 GIL \u9650\u5236\u3002\u4f46\u8fd9\u5f15\u5165\u4e86\u8fdb\u7a0b\u95f4\u901a\u4fe1\u7684\u5e8f\u5217\u5316\u5f00\u9500&#xff0c;\u5c0f\u7c92\u5ea6\u4efb\u52a1\u53cd\u800c\u66f4\u6162\u3002<\/p>\n<p>\u5f02\u6b65\u751f\u6001\u7684\u540c\u6b65\u9677\u9631&#xff1a;\u8bb8\u591a Python \u5e93\u7684&#034;\u5f02\u6b65\u7248\u672c&#034;\u53ea\u662f\u5728\u540c\u6b65\u8c03\u7528\u5916\u9762\u5305\u4e86\u4e00\u5c42 asyncio.to_thread&#xff0c;\u672c\u8d28\u4e0a\u8fd8\u662f\u7528\u7ebf\u7a0b\u6c60\u6a21\u62df\u5f02\u6b65\u3002\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u4ecd\u7136\u5360\u7528\u7ebf\u7a0b\u8d44\u6e90&#xff0c;\u9ad8\u5e76\u53d1\u4e0b\u53ef\u80fd\u8017\u5c3d\u7ebf\u7a0b\u6c60\u3002\u4f7f\u7528\u524d\u52a1\u5fc5\u786e\u8ba4\u5e93\u662f\u5426\u57fa\u4e8e\u539f\u751f\u5f02\u6b65 I\/O \u5b9e\u73b0&#xff08;\u5982 aiohttp \u800c\u975e requests&#xff09;\u3002<\/p>\n<p>\u8c03\u8bd5\u7684\u4e0d\u53ef\u91cd\u73b0\u6027&#xff1a;\u5f02\u6b65\u4ee3\u7801\u7684\u6267\u884c\u987a\u5e8f\u53d6\u51b3\u4e8e\u4e8b\u4ef6\u5faa\u73af\u7684\u8c03\u5ea6\u7b56\u7565\u548c I\/O \u4e8b\u4ef6\u7684\u5230\u8fbe\u65f6\u5e8f&#xff0c;\u5bfc\u81f4 Bug \u5f80\u5f80\u96be\u4ee5\u7a33\u5b9a\u590d\u73b0\u3002asyncio \u7684 debug \u6a21\u5f0f&#xff08;asyncio.run(main(), debug&#061;True)&#xff09;\u53ef\u4ee5\u68c0\u6d4b\u672a await \u7684\u534f\u7a0b\u548c\u8fc7\u957f\u7684\u540c\u6b65\u6267\u884c&#xff0c;\u4f46\u751f\u4ea7\u73af\u5883\u5f00\u542f debug \u6a21\u5f0f\u4f1a\u5e26\u6765\u7ea6 10% \u7684\u6027\u80fd\u635f\u8017\u3002<\/p>\n<p>\u9002\u7528\u8fb9\u754c&#xff1a;\u5f02\u6b65\u7f16\u7a0b\u9002\u5408 I\/O \u5bc6\u96c6\u578b\u573a\u666f&#xff08;HTTP \u8bf7\u6c42\u3001\u6570\u636e\u5e93\u67e5\u8be2\u3001\u6587\u4ef6\u8bfb\u5199&#xff09;\u3002CPU \u5bc6\u96c6\u578b\u573a\u666f&#xff08;\u6570\u503c\u8ba1\u7b97\u3001\u56fe\u50cf\u5904\u7406&#xff09;\u5e94\u4f18\u5148\u8003\u8651\u591a\u8fdb\u7a0b\u800c\u975e\u5f02\u6b65\u3002\u6df7\u5408\u578b\u573a\u666f&#xff08;I\/O &#043; \u5c11\u91cf\u8ba1\u7b97&#xff09;&#xff0c;\u5f02\u6b65 &#043; \u8fdb\u7a0b\u6c60\u7684\u7ec4\u5408\u662f\u5408\u7406\u9009\u62e9\u3002<\/p>\n<p>\u7981\u7528\u573a\u666f&#xff1a;\u670d\u52a1\u7684\u8bf7\u6c42\u5904\u7406\u903b\u8f91\u51e0\u4e4e\u5168\u662f\u540c\u6b65\u8ba1\u7b97\u65f6&#xff0c;\u5f3a\u884c\u5f02\u6b65\u5316\u53ea\u4f1a\u589e\u52a0\u4ee3\u7801\u590d\u6742\u5ea6\u800c\u65e0\u6cd5\u83b7\u5f97\u6027\u80fd\u6536\u76ca&#xff1b;\u56e2\u961f\u5bf9\u5f02\u6b65\u7f16\u7a0b\u6a21\u578b\u4e0d\u719f\u6089\u65f6&#xff0c;\u5f02\u6b65\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u98ce\u9669\u53ef\u80fd\u8d85\u8fc7\u6027\u80fd\u6536\u76ca\u3002<\/p>\n<h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<p>Python \u5f02\u6b65\u7f16\u7a0b\u7684\u6838\u5fc3\u673a\u5236\u662f\u4e8b\u4ef6\u5faa\u73af\u9a71\u52a8\u7684\u534f\u7a0b\u8c03\u5ea6\u2014\u2014\u901a\u8fc7 await \u8ba9\u51fa\u63a7\u5236\u6743&#xff0c;\u5728 I\/O \u7b49\u5f85\u671f\u95f4\u6267\u884c\u5176\u4ed6\u534f\u7a0b&#xff0c;\u4ece\u800c\u5728\u5355\u7ebf\u7a0b\u5185\u5b9e\u73b0\u9ad8\u5e76\u53d1\u3002\u751f\u4ea7\u7ea7\u5f02\u6b65\u7cfb\u7edf\u9700\u8981\u5173\u6ce8\u4e09\u4e2a\u8c03\u4f18\u7ef4\u5ea6&#xff1a;\u8fde\u63a5\u6c60\u7ba1\u7406&#xff08;\u603b\u6c60\u5927\u5c0f\u4e0e\u5355\u4e3b\u673a\u9650\u5236\u7684\u5e73\u8861&#xff09;\u3001\u91cd\u8bd5\u7b56\u7565&#xff08;\u6307\u6570\u9000\u907f\u4e0e\u53ef\u91cd\u8bd5\u72b6\u6001\u7801\u7684\u7cbe\u786e\u754c\u5b9a&#xff09;\u3001\u5e76\u53d1\u63a7\u5236&#xff08;\u5168\u5c40\u4e0e\u4e3b\u673a\u7ea7\u4fe1\u53f7\u91cf\u7684\u53cc\u5c42\u9650\u6d41&#xff09;\u3002<\/p>\n<p>\u843d\u5730\u8def\u7ebf\u5efa\u8bae&#xff1a;\u7b2c\u4e00\u6b65&#xff0c;\u5c06\u9ad8\u9891 I\/O \u8c03\u7528&#xff08;HTTP\u3001\u6570\u636e\u5e93&#xff09;\u4ece\u540c\u6b65\u66ff\u6362\u4e3a\u5f02\u6b65&#xff0c;\u9a8c\u8bc1\u5355\u63a5\u53e3\u5ef6\u8fdf\u6539\u5584&#xff1b;\u7b2c\u4e8c\u6b65&#xff0c;\u5f15\u5165\u8fde\u63a5\u6c60\u548c\u8d85\u65f6\u914d\u7f6e&#xff0c;\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f\u548c\u7ea7\u8054\u963b\u585e&#xff1b;\u7b2c\u4e09\u6b65&#xff0c;\u5b9e\u73b0\u6279\u91cf\u5e76\u53d1\u8bf7\u6c42\u7684\u4fe1\u53f7\u91cf\u63a7\u5236&#xff0c;\u63d0\u5347\u541e\u5410\u91cf&#xff1b;\u7b2c\u56db\u6b65&#xff0c;\u5bf9 CPU \u5bc6\u96c6\u578b\u4efb\u52a1\u4f7f\u7528 run_in_executor \u59d4\u6258\u8fdb\u7a0b\u6c60&#xff0c;\u907f\u514d\u4e8b\u4ef6\u5faa\u73af\u963b\u585e\u3002\u5f02\u6b65\u89e3\u51b3\u7684\u662f I\/O \u7b49\u5f85\u95ee\u9898&#xff0c;\u4e0d\u662f\u8ba1\u7b97\u901f\u5ea6\u95ee\u9898\u2014\u2014\u9009\u5bf9\u6218\u573a\u6bd4\u4f18\u5316\u624b\u6bb5\u66f4\u91cd\u8981\u3002<\/p>\n<hr \/>\n<p>\u6539\u5199\u603b\u7ed3&#xff1a;<\/p>\n<table>\n<tr>\u4fee\u6539\u9879\u539f\u6587\u95ee\u9898\u5904\u7406\u65b9\u5f0f<\/tr>\n<tbody>\n<tr>\n<td>\u6807\u9898\u4e2d\u7684&#034;\u5de5\u7a0b\u5b9e\u8df5&#034;<\/td>\n<td>\u8425\u9500\u5f0f\u8868\u8fbe<\/td>\n<td>\u5220\u9664<\/td>\n<\/tr>\n<tr>\n<td>&#034;\u6838\u5fc3\u4ef7\u503c\u4e0d\u662f&#039;\u66f4\u5feb&#039;&#034;<\/td>\n<td>\u5426\u5b9a\u5f0f\u6392\u6bd4<\/td>\n<td>\u4fdd\u7559\u4f46\u7b80\u5316\u8868\u8ff0<\/td>\n<\/tr>\n<tr>\n<td>&#034;\u5173\u952e\u8de8\u8d8a&#034;<\/td>\n<td>AI \u8bcd\u6c47<\/td>\n<td>\u6539\u4e3a&#034;\u5173\u952e&#034;<\/td>\n<\/tr>\n<tr>\n<td>&#034;\u5c55\u793a\u5f02\u6b65\u7f16\u7a0b\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u6700\u4f73\u5b9e\u8df5&#034;<\/td>\n<td>\u5ba3\u4f20\u6027\u8bed\u8a00<\/td>\n<td>\u5220\u9664<\/td>\n<\/tr>\n<tr>\n<td>\u591a\u5904\u7c97\u4f53\u5f3a\u8c03<\/td>\n<td>\u8fc7\u5ea6\u4f7f\u7528<\/td>\n<td>\u4fdd\u7559\u5fc5\u8981\u7684\u6280\u672f\u672f\u8bed\u7c97\u4f53<\/td>\n<\/tr>\n<tr>\n<td>&#034;\u4e0b\u9762\u5b9e\u73b0\u4e00\u4e2a&#8230;&#034;<\/td>\n<td>\u586b\u5145\u77ed\u8bed<\/td>\n<td>\u5220\u9664<\/td>\n<\/tr>\n<tr>\n<td>\u90e8\u5206\u7834\u6298\u53f7\u89e3\u91ca<\/td>\n<td>\u8fc7\u5ea6\u4f7f\u7528<\/td>\n<td>\u4fdd\u7559\u5fc5\u8981\u7684\u6280\u672f\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td>&#034;\u8fd9\u610f\u5473\u7740&#034;<\/td>\n<td>\u586b\u5145\u77ed\u8bed<\/td>\n<td>\u4fdd\u7559\u4f46\u7cbe\u7b80\u4e0a\u4e0b\u6587<\/td>\n<\/tr>\n<tr>\n<td>\u90e8\u5206\u4e09\u6bb5\u5f0f\u5217\u4e3e<\/td>\n<td>\u516c\u5f0f\u5316\u7ed3\u6784<\/td>\n<td>\u8c03\u6574\u4e3a\u4e24\u9879\u6216\u81ea\u7136\u8fc7\u6e21<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8d28\u91cf\u8bc4\u5206&#xff1a;\/50<\/p>\n<table>\n<tr>\u7ef4\u5ea6\u5f97\u5206<\/tr>\n<tbody>\n<tr>\n<td>\u76f4\u63a5\u6027<\/td>\n<td>8\/10<\/td>\n<\/tr>\n<tr>\n<td>\u8282\u594f<\/td>\n<td>7\/10<\/td>\n<\/tr>\n<tr>\n<td>\u4fe1\u4efb\u5ea6<\/td>\n<td>8\/10<\/td>\n<\/tr>\n<tr>\n<td>\u771f\u5b9e\u6027<\/td>\n<td>7\/10<\/td>\n<\/tr>\n<tr>\n<td>\u7cbe\u70bc\u5ea6<\/td>\n<td>8\/10<\/td>\n<\/tr>\n<tr>\n<td>\u603b\u5206<\/td>\n<td>38\/50<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5f02\u6b65\u7f16\u7a0b&#xff1a;\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18<br \/>\n\u4e00\u3001\u540c\u6b65\u963b\u585e\u7684\u4ee3\u4ef7<br \/>\n\u4e00\u4e2a\u5178\u578b\u7684 Python Web \u670d\u52a1\u5728\u5904\u7406\u6570\u636e\u5e93\u67e5\u8be2\u65f6&#xff0c;\u7ebf\u7a0b\u4f1a\u5728 I\/O \u7b49\u5f85\u671f\u95f4\u88ab\u5b8c\u5168\u5360\u7528\u3002\u5e76\u53d1\u8bf7\u6c42\u8fbe\u5230 200 \u65f6&#xff0c;\u7ebf\u7a0b\u6c60\u8017\u5c3d&#xff0c;\u65b0\u8bf7\u6c42\u6392\u961f\u7b49\u5f85&#xff0c;\u54cd\u5e94\u65f6\u95f4\u4ece 50ms \u98d9\u5347\u5230 3 \u79d2\u4ee5\u4e0a\u3002<br \/>\n\u540c\u6b65\u4ee3\u7801\u4e2d\u7684\u6bcf\u4e00\u6b21 requests.get() \u6216 db.execute()&#xff0c;\u90fd\u5728\u9690\u5f0f\u5730\u5236\u9020\u4e00\u4e2a\u963b\u585e\u70b9\u3002\u4f4e\u5e76\u53d1\u65f6\u8fd9\u4e9b\u963b\u585e\u70b9\u6ca1\u6709\u5b58<\/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":[50],"topic":[],"class_list":["post-81598","post","type-post","status-publish","format-standard","hentry","category-server","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 - \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\/81598.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\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Python \u5f02\u6b65\u7f16\u7a0b&#xff1a;\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 \u4e00\u3001\u540c\u6b65\u963b\u585e\u7684\u4ee3\u4ef7 \u4e00\u4e2a\u5178\u578b\u7684 Python Web \u670d\u52a1\u5728\u5904\u7406\u6570\u636e\u5e93\u67e5\u8be2\u65f6&#xff0c;\u7ebf\u7a0b\u4f1a\u5728 I\/O \u7b49\u5f85\u671f\u95f4\u88ab\u5b8c\u5168\u5360\u7528\u3002\u5e76\u53d1\u8bf7\u6c42\u8fbe\u5230 200 \u65f6&#xff0c;\u7ebf\u7a0b\u6c60\u8017\u5c3d&#xff0c;\u65b0\u8bf7\u6c42\u6392\u961f\u7b49\u5f85&#xff0c;\u54cd\u5e94\u65f6\u95f4\u4ece 50ms \u98d9\u5347\u5230 3 \u79d2\u4ee5\u4e0a\u3002 \u540c\u6b65\u4ee3\u7801\u4e2d\u7684\u6bcf\u4e00\u6b21 requests.get() \u6216 db.execute()&#xff0c;\u90fd\u5728\u9690\u5f0f\u5730\u5236\u9020\u4e00\u4e2a\u963b\u585e\u70b9\u3002\u4f4e\u5e76\u53d1\u65f6\u8fd9\u4e9b\u963b\u585e\u70b9\u6ca1\u6709\u5b58\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/81598.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-24T18:59:27+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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81598.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/81598.html\",\"name\":\"Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-24T18:59:27+00:00\",\"dateModified\":\"2026-07-24T18:59:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/81598.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/81598.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/81598.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18\"}]},{\"@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\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 - \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\/81598.html","og_locale":"zh_CN","og_type":"article","og_title":"Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Python \u5f02\u6b65\u7f16\u7a0b&#xff1a;\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 \u4e00\u3001\u540c\u6b65\u963b\u585e\u7684\u4ee3\u4ef7 \u4e00\u4e2a\u5178\u578b\u7684 Python Web \u670d\u52a1\u5728\u5904\u7406\u6570\u636e\u5e93\u67e5\u8be2\u65f6&#xff0c;\u7ebf\u7a0b\u4f1a\u5728 I\/O \u7b49\u5f85\u671f\u95f4\u88ab\u5b8c\u5168\u5360\u7528\u3002\u5e76\u53d1\u8bf7\u6c42\u8fbe\u5230 200 \u65f6&#xff0c;\u7ebf\u7a0b\u6c60\u8017\u5c3d&#xff0c;\u65b0\u8bf7\u6c42\u6392\u961f\u7b49\u5f85&#xff0c;\u54cd\u5e94\u65f6\u95f4\u4ece 50ms \u98d9\u5347\u5230 3 \u79d2\u4ee5\u4e0a\u3002 \u540c\u6b65\u4ee3\u7801\u4e2d\u7684\u6bcf\u4e00\u6b21 requests.get() \u6216 db.execute()&#xff0c;\u90fd\u5728\u9690\u5f0f\u5730\u5236\u9020\u4e00\u4e2a\u963b\u585e\u70b9\u3002\u4f4e\u5e76\u53d1\u65f6\u8fd9\u4e9b\u963b\u585e\u70b9\u6ca1\u6709\u5b58","og_url":"https:\/\/www.wsisp.com\/helps\/81598.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-24T18:59:27+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/81598.html","url":"https:\/\/www.wsisp.com\/helps\/81598.html","name":"Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-24T18:59:27+00:00","dateModified":"2026-07-24T18:59:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/81598.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/81598.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/81598.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python \u5f02\u6b65\u7f16\u7a0b\uff1a\u4ece\u534f\u7a0b\u8c03\u5ea6\u5230\u9ad8\u5e76\u53d1\u6027\u80fd\u8c03\u4f18"}]},{"@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\/81598","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=81598"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/81598\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=81598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=81598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=81598"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=81598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}