{"id":248,"date":"2026-09-10T10:04:18","date_gmt":"2026-09-10T02:04:18","guid":{"rendered":"https:\/\/yykcj.com\/?p=248"},"modified":"2026-09-10T10:04:18","modified_gmt":"2026-09-10T02:04:18","slug":"python-asyncio-%e6%b7%b1%e5%85%a5%e5%ae%9e%e6%88%98%ef%bc%9a%e4%bb%8e%e4%ba%8b%e4%bb%b6%e5%be%aa%e7%8e%af%e5%88%b0%e9%ab%98%e5%b9%b6%e5%8f%91%e7%88%ac%e8%99%ab","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=248","title":{"rendered":"Python asyncio \u6df1\u5165\u5b9e\u6218\uff1a\u4ece\u4e8b\u4ef6\u5faa\u73af\u5230\u9ad8\u5e76\u53d1\u722c\u866b"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u9700\u8981 asyncio\uff1f<\/h2>\n<p>\u5047\u8bbe\u4f60\u8981\u5199\u4e00\u4e2a\u722c\u866b\uff0c\u4e0b\u8f7d 100 \u5f20\u56fe\u7247\u3002\u4f20\u7edf\u7684\u540c\u6b65\u5199\u6cd5\u4f1a\u4e00\u5f20\u4e00\u5f20\u4e0b\u8f7d\uff0c\u6bcf\u5f20\u8017\u65f6 1 \u79d2\uff0c\u603b\u8017\u65f6 100 \u79d2\u3002\u800c\u4f7f\u7528\u591a\u7ebf\u7a0b\uff0c\u867d\u7136\u80fd\u5e76\u53d1\uff0c\u4f46\u7ebf\u7a0b\u5207\u6362\u5f00\u9500\u5927\uff0c\u4e14 GIL \u9650\u5236\u4e86 CPU \u5bc6\u96c6\u578b\u4efb\u52a1\u3002asyncio \u63d0\u4f9b\u4e86\u53e6\u4e00\u79cd\u601d\u8def\uff1a<strong>\u5355\u7ebf\u7a0b\u5185\u901a\u8fc7\u4e8b\u4ef6\u5faa\u73af\u8c03\u5ea6\u534f\u7a0b\uff0c\u5728 I\/O \u7b49\u5f85\u65f6\u81ea\u52a8\u5207\u6362\u4efb\u52a1<\/strong>\uff0c\u4ece\u800c\u7528\u6781\u5c11\u7684\u8d44\u6e90\u5b9e\u73b0\u9ad8\u5e76\u53d1\u3002<\/p>\n<p>\u4f46\u5f88\u591a\u521d\u5b66\u8005\u5bf9 asyncio \u7684\u7406\u89e3\u505c\u7559\u5728 <code>async\/await<\/code> \u8bed\u6cd5\u5c42\u9762\uff0c\u9047\u5230 <code>RuntimeError: This event loop is already running<\/code> \u6216\u4efb\u52a1\u672a\u6267\u884c\u5c31\u9000\u51fa\u7b49\u95ee\u9898\u65f6\u4e00\u5934\u96fe\u6c34\u3002\u672c\u6587\u5c06\u4ece\u4e8b\u4ef6\u5faa\u73af\u7684\u672c\u8d28\u8bb2\u8d77\uff0c\u5e26\u4f60\u624b\u5199\u4e00\u4e2a\u8ff7\u4f60\u4e8b\u4ef6\u5faa\u73af\uff0c\u518d\u9010\u6b65\u6784\u5efa\u4e00\u4e2a\u5f02\u6b65\u722c\u866b\uff0c\u6700\u540e\u7ed9\u51fa\u751f\u4ea7\u73af\u5883\u7684\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<h2>1. \u6838\u5fc3\u6982\u5ff5\uff1a\u534f\u7a0b\u3001\u4efb\u52a1\u4e0e\u4e8b\u4ef6\u5faa\u73af<\/h2>\n<h3>1.1 \u534f\u7a0b\uff08Coroutine\uff09<\/h3>\n<p>\u534f\u7a0b\u662f\u901a\u8fc7 <code>async def<\/code> \u5b9a\u4e49\u7684\u51fd\u6570\uff0c\u8c03\u7528\u5b83\u4e0d\u4f1a\u7acb\u5373\u6267\u884c\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2a\u534f\u7a0b\u5bf9\u8c61\u3002\u8981\u8fd0\u884c\u5b83\uff0c\u5fc5\u987b\u4ea4\u7ed9\u4e8b\u4ef6\u5faa\u73af\u3002<\/p>\n<pre><code class=\"language-python\">\nimport asyncio\n\nasync def hello():\n    print(&quot;Hello&quot;)\n    await asyncio.sleep(1)\n    print(&quot;World&quot;)\n\n# \u76f4\u63a5\u8c03\u7528 hello() \u53ea\u4f1a\u8fd4\u56de\u534f\u7a0b\u5bf9\u8c61\uff0c\u4e0d\u4f1a\u6267\u884c\ncoro = hello()\nprint(coro)  # &lt;coroutine object hello at 0x...&gt;\n\n# \u6b63\u786e\u65b9\u5f0f\uff1aasyncio.run \u521b\u5efa\u4e8b\u4ef6\u5faa\u73af\u5e76\u8fd0\u884c\nasyncio.run(hello())\n<\/code><\/pre>\n<h3>1.2 \u4efb\u52a1\uff08Task\uff09<\/h3>\n<p>\u4efb\u52a1\u662f\u5bf9\u534f\u7a0b\u7684\u5c01\u88c5\uff0c\u5b83\u4f1a\u88ab\u4e8b\u4ef6\u5faa\u73af\u8c03\u5ea6\u6267\u884c\u3002<code>asyncio.create_task()<\/code> \u5c06\u534f\u7a0b\u5305\u88c5\u4e3a\u4efb\u52a1\u5e76\u7acb\u5373\u6392\u5165\u4e8b\u4ef6\u5faa\u73af\u3002<\/p>\n<pre><code class=\"language-python\">\nasync def main():\n    task1 = asyncio.create_task(hello())\n    task2 = asyncio.create_task(hello())\n    await task1\n    await task2\n\nasyncio.run(main())\n<\/code><\/pre>\n<h3>1.3 \u4e8b\u4ef6\u5faa\u73af\uff08Event Loop\uff09<\/h3>\n<p>\u4e8b\u4ef6\u5faa\u73af\u662f asyncio \u7684\u5fc3\u810f\uff0c\u5b83\u8d1f\u8d23\uff1a<\/p>\n<ul>\n<li>\u6ce8\u518c\u4efb\u52a1\u548c\u56de\u8c03<\/li>\n<li>\u5728 I\/O \u5c31\u7eea\u65f6\u8c03\u5ea6\u5bf9\u5e94\u4efb\u52a1<\/li>\n<li>\u5904\u7406\u5b9a\u65f6\u5668<\/li>\n<\/ul>\n<p>\u4e00\u4e2a\u7ebf\u7a0b\u53ea\u80fd\u6709\u4e00\u4e2a\u8fd0\u884c\u4e2d\u7684\u4e8b\u4ef6\u5faa\u73af\u3002<code>asyncio.run()<\/code> \u4f1a\u521b\u5efa\u65b0\u5faa\u73af\uff0c\u8fd0\u884c\u5b8c\u540e\u5173\u95ed\u3002<\/p>\n<h2>2. \u624b\u5199\u8ff7\u4f60\u4e8b\u4ef6\u5faa\u73af\uff1a\u7406\u89e3\u8c03\u5ea6\u539f\u7406<\/h2>\n<p>\u4e3a\u4e86\u900f\u5f7b\u7406\u89e3\uff0c\u6211\u4eec\u7528\u751f\u6210\u5668\u6a21\u62df\u4e00\u4e2a\u6781\u7b80\u4e8b\u4ef6\u5faa\u73af\u3002<\/p>\n<pre><code class=\"language-python\">\nimport time\nfrom collections import deque\n\nclass MiniEventLoop:\n    def __init__(self):\n        self._ready = deque()  # \u5c31\u7eea\u4efb\u52a1\u961f\u5217\n        self._sleeping = []    # \u7761\u7720\u4e2d\u7684\u4efb\u52a1 (\u5524\u9192\u65f6\u95f4, \u4efb\u52a1)\n\n    def call_soon(self, callback, *args):\n        &quot;&quot;&quot;\u5c06\u56de\u8c03\u52a0\u5165\u5c31\u7eea\u961f\u5217&quot;&quot;&quot;\n        self._ready.append((callback, args))\n\n    def call_later(self, delay, callback, *args):\n        &quot;&quot;&quot;\u5ef6\u8fdf\u6267\u884c&quot;&quot;&quot;\n        self._sleeping.append((time.time() + delay, callback, args))\n\n    def run_forever(self):\n        while self._ready or self._sleeping:\n            # \u5904\u7406\u5df2\u5c31\u7eea\u7684\u56de\u8c03\n            while self._ready:\n                callback, args = self._ready.popleft()\n                callback(*args)\n\n            # \u5904\u7406\u7761\u7720\u4efb\u52a1\n            if self._sleeping:\n                self._sleeping.sort(key=lambda x: x[0])\n                now = time.time()\n                while self._sleeping and self._sleeping[0][0] &lt;= now:\n                    _, callback, args = self._sleeping.pop(0)\n                    callback(*args)\n                else:\n                    # \u6ca1\u6709\u5c31\u7eea\u4efb\u52a1\u65f6\uff0c\u7b49\u5f85\u6700\u8fd1\u7684\u4efb\u52a1\n                    if self._sleeping and not self._ready:\n                        sleep_time = self._sleeping[0][0] - time.time()\n                        if sleep_time &gt; 0:\n                            time.sleep(sleep_time)\n\n# \u4f7f\u7528\u793a\u4f8b\ndef task1():\n    print(&quot;Task 1 start&quot;)\n    loop.call_later(1, task1_continue)\n\ndef task1_continue():\n    print(&quot;Task 1 continue after 1s&quot;)\n\ndef task2():\n    print(&quot;Task 2 start&quot;)\n\nloop = MiniEventLoop()\nloop.call_soon(task1)\nloop.call_soon(task2)\nloop.run_forever()\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u8ff7\u4f60\u5faa\u73af\u867d\u7136\u7b80\u5355\uff0c\u4f46\u63ed\u793a\u4e86 asyncio \u7684\u6838\u5fc3\uff1a<strong>\u5c31\u7eea\u961f\u5217 + \u5b9a\u65f6\u5668\u7ba1\u7406<\/strong>\u3002\u771f\u6b63\u7684 asyncio \u4f7f\u7528 <code>select\/epoll\/kqueue<\/code> \u76d1\u542c I\/O \u4e8b\u4ef6\uff0c\u5e76\u96c6\u6210 Future \u548c\u534f\u7a0b\u9a71\u52a8\u3002<\/p>\n<h2>3. \u6df1\u5165 async\/await \u6267\u884c\u6d41\u7a0b<\/h2>\n<p><code>await<\/code> \u8868\u8fbe\u5f0f\u4f1a\u6302\u8d77\u5f53\u524d\u534f\u7a0b\uff0c\u5c06\u63a7\u5236\u6743\u4ea4\u8fd8\u7ed9\u4e8b\u4ef6\u5faa\u73af\u3002\u5f53\u88ab\u7b49\u5f85\u7684\u5bf9\u8c61\u5b8c\u6210\u65f6\uff0c\u4e8b\u4ef6\u5faa\u73af\u518d\u6062\u590d\u534f\u7a0b\u3002<\/p>\n<pre><code class=\"language-python\">\nimport asyncio\n\nasync def compute(x, y):\n    print(f&quot;Compute {x} + {y} ...&quot;)\n    await asyncio.sleep(1)  # \u6a21\u62df I\/O \u7b49\u5f85\n    return x + y\n\nasync def main():\n    # \u5e76\u53d1\u8fd0\u884c\u4e24\u4e2a\u534f\u7a0b\n    result = await asyncio.gather(compute(1, 2), compute(3, 4))\n    print(result)  # [3, 7]\n\nasyncio.run(main())\n<\/code><\/pre>\n<p><code>asyncio.gather<\/code> \u5c06\u591a\u4e2a\u534f\u7a0b\u5305\u88c5\u4e3a\u4efb\u52a1\u5e76\u53d1\u6267\u884c\uff0c\u5e76\u6536\u96c6\u7ed3\u679c\u3002\u6ce8\u610f\uff1a<strong>gather \u8fd4\u56de\u7684\u7ed3\u679c\u987a\u5e8f\u4e0e\u4f20\u5165\u987a\u5e8f\u4e00\u81f4\uff0c\u4e0e\u5b8c\u6210\u987a\u5e8f\u65e0\u5173<\/strong>\u3002<\/p>\n<h2>4. \u5b9e\u6218\uff1a\u5f02\u6b65\u722c\u866b\uff08aiohttp + asyncio\uff09<\/h2>\n<p>\u4e0b\u9762\u6211\u4eec\u6784\u5efa\u4e00\u4e2a\u5f02\u6b65\u722c\u866b\uff0c\u6293\u53d6\u591a\u4e2a\u7f51\u9875\u7684\u6807\u9898\u3002\u4f7f\u7528 <code>aiohttp<\/code> \u5e93\u3002<\/p>\n<h3>4.1 \u5b89\u88c5\u4f9d\u8d56<\/h3>\n<pre><code class=\"language-bash\">\npip install aiohttp beautifulsoup4\n<\/code><\/pre>\n<h3>4.2 \u57fa\u7840\u7248\u672c<\/h3>\n<pre><code class=\"language-python\">\nimport asyncio\nimport aiohttp\nfrom bs4 import BeautifulSoup\n\nasync def fetch_title(session, url):\n    async with session.get(url) as response:\n        html = await response.text()\n        soup = BeautifulSoup(html, &#x27;html.parser&#x27;)\n        title = soup.title.string if soup.title else &#x27;No title&#x27;\n        return url, title\n\nasync def main(urls):\n    async with aiohttp.ClientSession() as session:\n        tasks = [fetch_title(session, url) for url in urls]\n        results = await asyncio.gather(*tasks)\n        for url, title in results:\n            print(f&quot;{url}: {title}&quot;)\n\nif __name__ == &#x27;__main__&#x27;:\n    urls = [\n        &#x27;https:\/\/www.python.org&#x27;,\n        &#x27;https:\/\/www.github.com&#x27;,\n        &#x27;https:\/\/www.stackoverflow.com&#x27;\n    ]\n    asyncio.run(main(urls))\n<\/code><\/pre>\n<h3>4.3 \u63a7\u5236\u5e76\u53d1\u6570<\/h3>\n<p>\u76f4\u63a5 <code>gather<\/code> \u6240\u6709\u8bf7\u6c42\u53ef\u80fd\u538b\u57ae\u76ee\u6807\u670d\u52a1\u5668\u6216\u89e6\u53d1\u9650\u5236\u3002\u4f7f\u7528 <code>asyncio.Semaphore<\/code> \u9650\u5236\u5e76\u53d1\u6570\u3002<\/p>\n<pre><code class=\"language-python\">\nasync def fetch_title(session, url, sem):\n    async with sem:\n        async with session.get(url) as response:\n            html = await response.text()\n            soup = BeautifulSoup(html, &#x27;html.parser&#x27;)\n            title = soup.title.string if soup.title else &#x27;No title&#x27;\n            return url, title\n\nasync def main(urls, concurrency=5):\n    sem = asyncio.Semaphore(concurrency)\n    async with aiohttp.ClientSession() as session:\n        tasks = [fetch_title(session, url, sem) for url in urls]\n        results = await asyncio.gather(*tasks, return_exceptions=True)\n        for res in results:\n            if isinstance(res, Exception):\n                print(f&quot;Error: {res}&quot;)\n            else:\n                print(f&quot;{res[0]}: {res[1]}&quot;)\n<\/code><\/pre>\n<h3>4.4 \u8d85\u65f6\u4e0e\u91cd\u8bd5<\/h3>\n<p>\u7f51\u7edc\u8bf7\u6c42\u5fc5\u987b\u8bbe\u7f6e\u8d85\u65f6\uff0c\u5e76\u8003\u8651\u91cd\u8bd5\u3002<\/p>\n<pre><code class=\"language-python\">\nimport asyncio\nfrom aiohttp import ClientTimeout\n\nasync def fetch_with_retry(session, url, sem, retries=3):\n    async with sem:\n        for attempt in range(retries):\n            try:\n                timeout = ClientTimeout(total=10)\n                async with session.get(url, timeout=timeout) as response:\n                    html = await response.text()\n                    soup = BeautifulSoup(html, &#x27;html.parser&#x27;)\n                    title = soup.title.string if soup.title else &#x27;No title&#x27;\n                    return url, title\n            except Exception as e:\n                if attempt == retries - 1:\n                    raise\n                await asyncio.sleep(1 * (attempt + 1))  # \u6307\u6570\u9000\u907f\n<\/code><\/pre>\n<h2>5. \u5e38\u89c1\u9677\u9631\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h2>\n<h3>5.1 \u963b\u585e\u8c03\u7528\u963b\u585e\u6574\u4e2a\u4e8b\u4ef6\u5faa\u73af<\/h3>\n<p>\u5728\u534f\u7a0b\u4e2d\u8c03\u7528\u540c\u6b65\u963b\u585e\u51fd\u6570\uff08\u5982 <code>time.sleep<\/code>\u3001<code>requests.get<\/code>\uff09\u4f1a\u963b\u585e\u4e8b\u4ef6\u5faa\u73af\uff0c\u5bfc\u81f4\u6240\u6709\u4efb\u52a1\u5361\u4f4f\u3002<\/p>\n<p><strong>\u9519\u8bef\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-python\">\nasync def bad():\n    time.sleep(5)  # \u963b\u585e\u4e8b\u4ef6\u5faa\u73af\uff01\n<\/code><\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong>\uff1a\u4f7f\u7528 <code>asyncio.to<em>thread<\/code> \u6216 <code>run<\/em>in_executor<\/code> \u5c06\u963b\u585e\u8c03\u7528\u653e\u5230\u7ebf\u7a0b\u6c60\u3002<\/p>\n<pre><code class=\"language-python\">\nasync def good():\n    await asyncio.to_thread(time.sleep, 5)  # \u4e0d\u963b\u585e\u4e8b\u4ef6\u5faa\u73af\n<\/code><\/pre>\n<h3>5.2 \u5fd8\u8bb0 await \u5bfc\u81f4\u4efb\u52a1\u672a\u6267\u884c<\/h3>\n<pre><code class=\"language-python\">\nasync def main():\n    asyncio.create_task(hello())  # \u521b\u5efa\u4efb\u52a1\u4f46\u672a\u7b49\u5f85\n    # \u5982\u679c main \u5f88\u5feb\u7ed3\u675f\uff0c\u4efb\u52a1\u53ef\u80fd\u672a\u5b8c\u6210\n\nasyncio.run(main())\n<\/code><\/pre>\n<p><strong>\u4fee\u590d<\/strong>\uff1a\u4fdd\u5b58\u4efb\u52a1\u5f15\u7528\u5e76 <code>await<\/code>\uff0c\u6216\u4f7f\u7528 <code>asyncio.gather<\/code>\u3002<\/p>\n<h3>5.3 \u5728\u540c\u6b65\u4ee3\u7801\u4e2d\u8c03\u7528\u5f02\u6b65\u51fd\u6570<\/h3>\n<p>\u4e0d\u80fd\u5728\u666e\u901a\u51fd\u6570\u4e2d\u76f4\u63a5 <code>await<\/code>\u3002\u5fc5\u987b\u901a\u8fc7 <code>asyncio.run()<\/code> \u6216 <code>loop.run<em>until<\/em>complete()<\/code> \u542f\u52a8\u4e8b\u4ef6\u5faa\u73af\u3002<\/p>\n<h3>5.4 \u4f7f\u7528 asyncio.Queue \u5b9e\u73b0\u751f\u4ea7\u8005-\u6d88\u8d39\u8005<\/h3>\n<pre><code class=\"language-python\">\nimport asyncio\nimport random\n\nasync def producer(queue):\n    for i in range(5):\n        await asyncio.sleep(0.5)\n        item = random.randint(1, 100)\n        await queue.put(item)\n        print(f&quot;Produced {item}&quot;)\n    await queue.put(None)  # \u7ed3\u675f\u4fe1\u53f7\n\nasync def consumer(queue):\n    while True:\n        item = await queue.get()\n        if item is None:\n            break\n        print(f&quot;Consumed {item}&quot;)\n        await asyncio.sleep(1)\n\nasync def main():\n    queue = asyncio.Queue(maxsize=3)\n    await asyncio.gather(producer(queue), consumer(queue))\n\nasyncio.run(main())\n<\/code><\/pre>\n<h2>6. \u6027\u80fd\u5bf9\u6bd4\uff1a\u540c\u6b65 vs \u591a\u7ebf\u7a0b vs asyncio<\/h2>\n<p>\u6211\u4eec\u6a21\u62df 100 \u4e2a I\/O \u4efb\u52a1\uff08\u6bcf\u4e2a\u7b49\u5f85 0.1 \u79d2\uff09\uff0c\u6bd4\u8f83\u4e09\u79cd\u65b9\u5f0f\u3002<\/p>\n<pre><code class=\"language-python\">\nimport asyncio\nimport time\nimport requests\nfrom concurrent.futures import ThreadPoolExecutor\n\n# \u540c\u6b65\nstart = time.time()\nfor _ in range(100):\n    time.sleep(0.1)\nprint(f&quot;Sync: {time.time() - start:.2f}s&quot;)  # ~10s\n\n# \u591a\u7ebf\u7a0b\nstart = time.time()\nwith ThreadPoolExecutor(max_workers=10) as executor:\n    list(executor.map(lambda _: time.sleep(0.1), range(100)))\nprint(f&quot;Thread: {time.time() - start:.2f}s&quot;)  # ~1s\n\n# asyncio\nasync def io_task():\n    await asyncio.sleep(0.1)\n\nasync def async_main():\n    await asyncio.gather(*(io_task() for _ in range(100)))\n\nstart = time.time()\nasyncio.run(async_main())\nprint(f&quot;Asyncio: {time.time() - start:.2f}s&quot;)  # ~0.1s\n<\/code><\/pre>\n<p>\u7ed3\u679c\uff1aasyncio \u8fdc\u80dc\u540c\u6b65\uff0c\u4e14\u6bd4\u591a\u7ebf\u7a0b\u66f4\u8f7b\u91cf\u3002\u4f46\u6ce8\u610f\uff1a<strong>asyncio \u53ea\u9002\u7528\u4e8e I\/O \u5bc6\u96c6\u578b\u4efb\u52a1<\/strong>\uff0cCPU \u5bc6\u96c6\u578b\u4ecd\u9700\u591a\u8fdb\u7a0b\u3002<\/p>\n<h2>7. \u603b\u7ed3<\/h2>\n<ul>\n<li>asyncio \u901a\u8fc7\u4e8b\u4ef6\u5faa\u73af\u5728\u5355\u7ebf\u7a0b\u5185\u5b9e\u73b0\u5e76\u53d1\uff0c\u9002\u5408 I\/O \u5bc6\u96c6\u578b\u573a\u666f\u3002<\/li>\n<li>\u534f\u7a0b\u662f\u6838\u5fc3\uff0c<code>await<\/code> \u6302\u8d77\u534f\u7a0b\uff0c<code>create_task<\/code> \u8c03\u5ea6\u4efb\u52a1\u3002<\/li>\n<li>\u907f\u514d\u963b\u585e\u4e8b\u4ef6\u5faa\u73af\uff0c\u7528 <code>to_thread<\/code> \u5904\u7406\u540c\u6b65\u963b\u585e\u8c03\u7528\u3002<\/li>\n<li>\u4f7f\u7528 <code>Semaphore<\/code> \u63a7\u5236\u5e76\u53d1\uff0c<code>gather<\/code> \u6536\u96c6\u7ed3\u679c\uff0c<code>Queue<\/code> \u5b9e\u73b0\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u3002<\/li>\n<li>\u6027\u80fd\u5bf9\u6bd4\u663e\u793a asyncio \u5728\u9ad8\u5e76\u53d1 I\/O \u4e0b\u4f18\u52bf\u660e\u663e\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u4e00\u6b65\u53ef\u4ee5\u5b66\u4e60 <code>uvloop<\/code> \u63d0\u5347\u4e8b\u4ef6\u5faa\u73af\u6027\u80fd\uff0c\u6216\u7814\u7a76 <code>asyncio<\/code> \u4e0e\u591a\u8fdb\u7a0b\u7ed3\u5408\u5904\u7406 CPU \u5bc6\u96c6\u578b\u4efb\u52a1\u3002<\/p>\n<p><strong>\u5ef6\u4f38\u9605\u8bfb<\/strong>\uff1a<\/p>\n<ul>\n<li>Python \u5b98\u65b9\u6587\u6863 asyncio \u7ae0\u8282<\/li>\n<li>\u300aUsing Asyncio in Python\u300bby Caleb Hattingh<\/li>\n<li>aiohttp \u5b98\u65b9\u6587\u6863<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u5256\u6790 asyncio \u7684\u6838\u5fc3\u673a\u5236\uff0c\u901a\u8fc7\u624b\u5199\u8ff7\u4f60\u4e8b\u4ef6\u5faa\u73af\u7406\u89e3\u534f\u7a0b\u8c03\u5ea6\uff0c\u5e76\u9010\u6b65\u6784\u5efa\u4e00\u4e2a\u5f02\u6b65\u722c\u866b\u3002\u5305\u542b\u5e38\u89c1\u9677\u9631\u4e0e\u6027\u80fd\u4f18\u5316\u6280\u5de7\uff0c\u52a9\u4f60\u638c\u63e1 Python \u5f02\u6b65\u7f16\u7a0b\u7cbe\u9ad3\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[102,86,104,103,215],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-asyncio","tag-python","tag-104","tag-103","tag-215"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=248"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/248\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}