{"id":119457,"date":"2026-10-29T18:32:45","date_gmt":"2026-10-29T10:32:45","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/119457.html"},"modified":"2026-10-29T18:32:45","modified_gmt":"2026-10-29T10:32:45","slug":"receive-%e5%8f%96%e6%b6%88%e4%ba%86%ef%bc%8ctcp-%e4%b8%ba%e4%bb%80%e4%b9%88%e8%bf%98%e5%9c%a8%e8%af%bb%ef%bc%9aanyio-%e7%9a%84%e4%b8%80%e6%ac%a1%e8%83%8c%e5%8e%8b%e4%bf%ae%e5%a4%8d","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/119457.html","title":{"rendered":"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d"},"content":{"rendered":"<p>\u7ed9\u4e00\u6b21\u7f51\u7edc\u63a5\u6536\u52a0\u4e0a\u8d85\u65f6&#xff0c;\u8d85\u65f6\u4e4b\u540e\u53bb\u505a\u522b\u7684\u4e8b&#xff0c;\u8fde\u63a5\u7559\u7740\u4e0b\u6b21\u518d\u7528\u3002\u8fd9\u662f\u5f88\u5e73\u5e38\u7684\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token keyword\">with<\/span> anyio<span class=\"token punctuation\">.<\/span>move_on_after<span class=\"token punctuation\">(<\/span><span class=\"token number\">0.1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> stream<span class=\"token punctuation\">.<\/span>receive<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6682\u65f6\u4e0d\u518d\u63a5\u6536&#xff0c;\u4f46\u4fdd\u7559\u8fd9\u6761\u8fde\u63a5<\/span><\/p>\n<p>\u5728\u4fee\u590d\u524d\u7684 AnyIO asyncio \u540e\u7aef\u91cc&#xff0c;\u8fd9\u91cc\u4f1a\u7559\u4e0b\u4e00\u4e2a\u4e0d\u592a\u663e\u773c\u7684\u72b6\u6001&#xff1a;receive() \u5df2\u7ecf\u56e0\u8d85\u65f6\u9000\u51fa&#xff0c;\u5e95\u5c42 TCP transport \u5374\u4ecd\u7136\u5728\u8bfb\u3002\u5bf9\u7aef\u968f\u540e\u53d1\u6765\u7684\u6570\u636e&#xff0c;\u7ee7\u7eed\u8fdb\u5165 Python \u4e2d\u7684\u63a5\u6536\u961f\u5217&#xff0c;\u54ea\u6015\u5e94\u7528\u5df2\u7ecf\u6ca1\u6709\u4eba\u6d88\u8d39\u5b83\u3002<\/p>\n<p>\u53d6\u6d88\u4e86\u7b49\u5f85&#xff0c;\u4e0d\u7b49\u4e8e\u64a4\u9500\u4e86\u7b49\u5f85\u524d\u5f00\u542f\u7684\u8bfb\u53d6\u3002<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u5728 AnyIO #1424 \u4e2d\u4fee\u590d&#xff0c;2026 \u5e74 10 \u6708 18 \u65e5\u5408\u5e76\u3002\u751f\u4ea7\u4ee3\u7801\u53ea\u7ed9\u4e00\u4e2a await \u52a0\u4e0a\u4e86 try\/finally\u3002\u8981\u770b\u6e05\u8fd9\u4e24\u884c\u4e3a\u4ec0\u4e48\u6709\u7528&#xff0c;\u5f97\u5148\u628a\u201c\u5e94\u7528\u5728\u63a5\u6536\u201d\u548c\u201c\u5e95\u5c42\u5728\u8bfb\u53d6\u201d\u5206\u5f00\u3002<\/p>\n<h3>\u4e00\u3001\u5e94\u7528\u6ca1\u8c03\u7528 receive&#xff0c;\u6570\u636e\u4e5f\u53ef\u80fd\u8fdb\u5165 Python<\/h3>\n<p>\u4e00\u6761 TCP \u8fde\u63a5\u91cc\u7684\u6570\u636e\u4e0d\u662f\u4ece\u7f51\u7edc\u76f4\u63a5\u8df3\u5230 await stream.receive() \u7684\u8fd4\u56de\u503c\u91cc\u3002AnyIO \u7684\u8fd9\u6761 asyncio \u8def\u5f84\u4e2d\u95f4\u6709\u51e0\u5c42&#xff1a;<\/p>\n<ul>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u5148\u63a5\u6536 TCP \u6570\u636e&#xff0c;\u653e\u8fdb\u5185\u6838\u7f13\u51b2\u3002<\/li>\n<li>asyncio \u7684 transport \u628a\u8bfb\u5230\u7684\u6570\u636e\u4ea4\u7ed9 protocol \u7684 data_received() \u56de\u8c03\u3002<\/li>\n<li>AnyIO \u7684 protocol \u628a\u6570\u636e\u653e\u8fdb read_queue&#xff0c;\u5e94\u7528\u7684 receive() \u518d\u4ece\u961f\u5217\u4e2d\u53d6\u8d70\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u7684 protocol \u662f asyncio \u7684\u56de\u8c03\u63a5\u53e3&#xff0c;\u4e0d\u662f\u53c8\u5957\u4e86\u4e00\u5c42\u7f51\u7edc\u534f\u8bae\u3002\u5b83\u63a5\u6536 transport \u4ea4\u4e0a\u6765\u7684\u5b57\u8282&#xff0c;\u6e90\u7801\u4e2d\u5bf9\u5e94\u7684\u5904\u7406\u5f88\u77ed&#xff08;StreamProtocol&#xff0c;\u8282\u9009&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5efa\u7acb\u8fde\u63a5\u65f6<\/span><br \/>\nself<span class=\"token punctuation\">.<\/span>read_queue <span class=\"token operator\">&#061;<\/span> deque<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># transport \u4ea4\u6765\u6570\u636e\u65f6<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">data_received<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">bytes<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    self<span class=\"token punctuation\">.<\/span>read_queue<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span><span class=\"token builtin\">bytes<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    self<span class=\"token punctuation\">.<\/span>read_event<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>read_event \u7528\u6765\u53eb\u9192\u7b49\u5f85\u4e2d\u7684\u63a5\u6536\u8005&#xff1b;read_queue \u7528\u6765\u4fdd\u5b58\u6570\u636e\u3002\u8fd9\u4e2a deque() \u6ca1\u6709\u8bbe\u7f6e\u5bb9\u91cf\u4e0a\u9650&#xff0c;data_received() \u91cc\u4e5f\u6ca1\u6709\u201c\u961f\u5217\u8d85\u8fc7\u67d0\u4e2a\u5927\u5c0f\u5c31\u6682\u505c\u201d\u7684\u5224\u65ad\u3002<\/p>\n<p>\u90a3\u6b63\u5e38\u60c5\u51b5\u4e0b&#xff0c;\u8c01\u6765\u963b\u6b62\u5b83\u4e00\u76f4\u589e\u957f&#xff1f;\u7b54\u6848\u5728 receive()\u3002AnyIO \u5e76\u4e0d\u662f\u59cb\u7ec8\u5f00\u7740\u8bfb\u53d6\u3001\u7b49\u961f\u5217\u6ee1\u4e86\u518d\u505c&#xff0c;\u800c\u662f\u5728\u9700\u8981\u7b49\u65b0\u6570\u636e\u65f6\u6062\u590d\u8bfb\u53d6&#xff0c;\u7b49\u5230\u6570\u636e\u540e\u518d\u6682\u505c\u3002\u5ba2\u6237\u7aef\u8fde\u63a5\u521a\u5efa\u597d\u65f6&#xff0c;\u4e5f\u4f1a\u5148\u8c03\u7528\u4e00\u6b21 pause_reading()&#xff08;connect_tcp&#xff09;\u3002<\/p>\n<p>pause_reading() \u6682\u505c\u7684\u662f transport \u5411 protocol \u4ea4\u4ed8\u6570\u636e\u3002\u8fd9\u8ba9\u5e94\u7528\u6682\u65f6\u4e0d\u6d88\u8d39\u65f6&#xff0c;\u6570\u636e\u4e0d\u518d\u6e90\u6e90\u4e0d\u65ad\u5730\u642c\u8fdb\u8fd9\u4e2a Python \u961f\u5217&#xff1b;\u968f\u7740\u5185\u6838\u63a5\u6536\u7f13\u51b2\u586b\u6ee1&#xff0c;TCP \u7684\u6d41\u91cf\u63a7\u5236\u4f1a\u9010\u6b65\u628a\u538b\u529b\u4f20\u56de\u53d1\u9001\u7aef\u3002\u8fd9\u5c31\u662f\u8fd9\u91cc\u7684\u80cc\u538b&#xff1a;\u63a5\u6536\u8005\u5904\u7406\u4e0d\u8fc7\u6765&#xff0c;\u4e0d\u80fd\u9760\u672c\u8fdb\u7a0b\u65e0\u9650\u5b58\u7740\u6765\u63a9\u76d6\u3002<\/p>\n<p>\u6682\u505c\u8bfb\u53d6\u5e76\u4e0d\u7b49\u4e8e\u5173\u95ed\u8fde\u63a5&#xff0c;\u4e5f\u4e0d\u4fdd\u8bc1\u5bf9\u7aef\u4e0b\u4e00\u6b21 send() \u7acb\u523b\u5361\u4f4f\u3002\u5185\u6838\u7f13\u51b2\u3001\u5bf9\u7aef\u7684\u53d1\u9001\u7f13\u51b2\u548c\u5728\u9014\u6570\u636e\u4ecd\u7136\u5b58\u5728\u3002\u5b83\u9996\u5148\u5173\u6389\u7684\u662f\u201c\u7ee7\u7eed\u628a\u6570\u636e\u4ea4\u7ed9\u8fd9\u4e2a protocol\u201d\u7684\u5165\u53e3&#xff08;asyncio ReadTransport \u6587\u6863&#xff09;\u3002<\/p>\n<h3>\u4e8c\u3001\u6f0f\u6389\u7684\u4e0d\u662f\u53d6\u6d88&#xff0c;\u800c\u662f\u53d6\u6d88\u540e\u7684\u6682\u505c<\/h3>\n<p>\u4fee\u590d\u524d&#xff0c;receive() \u5728\u9700\u8981\u7b49\u5f85\u65b0\u6570\u636e\u7684\u5206\u652f\u91cc\u505a\u8fd9\u4e09\u4ef6\u4e8b&#xff08;\u4fee\u524d\u6e90\u7801&#xff09;&#xff1a;<\/p>\n<p>self<span class=\"token punctuation\">.<\/span>_transport<span class=\"token punctuation\">.<\/span>resume_reading<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">await<\/span> self<span class=\"token punctuation\">.<\/span>_protocol<span class=\"token punctuation\">.<\/span>read_event<span class=\"token punctuation\">.<\/span>wait<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nself<span class=\"token punctuation\">.<\/span>_transport<span class=\"token punctuation\">.<\/span>pause_reading<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u6ca1\u6709\u53d6\u6d88\u65f6&#xff0c;\u8fd9\u6bb5\u903b\u8f91\u5f88\u597d\u7406\u89e3&#xff1a;\u6253\u5f00\u8bfb\u53d6&#xff0c;\u7b49\u6570\u636e\u5230\u8fbe&#xff0c;\u6682\u505c\u8bfb\u53d6&#xff0c;\u7136\u540e\u4ece\u961f\u5217\u53d6\u51fa\u4e00\u5757\u6570\u636e\u8fd4\u56de\u3002\u5982\u679c\u4e00\u5757\u592a\u5927&#xff0c;\u5c31\u5207\u51fa max_bytes&#xff0c;\u628a\u4f59\u4e0b\u7684\u90e8\u5206\u653e\u56de\u961f\u9996\u3002<\/p>\n<p>\u95ee\u9898\u662f&#xff0c;\u4e2d\u95f4\u7684 await \u4e0d\u4fdd\u8bc1\u6b63\u5e38\u8fd4\u56de\u3002<\/p>\n<p>move_on_after() \u5230\u671f\u4f1a\u53d6\u6d88\u5b83\u5305\u56f4\u7684\u64cd\u4f5c\u3002\u5f53\u63a5\u6536\u4efb\u52a1\u963b\u585e\u5728 read_event.wait() \u65f6&#xff0c;\u53d6\u6d88\u5f02\u5e38\u4ece\u8fd9\u4e2a\u7b49\u5f85\u70b9\u629b\u51fa\u6765&#xff0c;\u63a7\u5236\u6d41\u76f4\u63a5\u79bb\u5f00&#xff0c;\u4e0b\u4e00\u884c pause_reading() \u6839\u672c\u6ca1\u6709\u6267\u884c\u3002receive() \u9000\u51fa\u4e86&#xff0c;\u4f46\u5b83\u4e4b\u524d\u5bf9 transport \u505a\u7684\u72b6\u6001\u4fee\u6539\u8fd8\u5728\u3002<\/p>\n<p>\u8fd9\u65f6&#xff0c;\u5bf9\u7aef\u518d\u53d1\u6765\u6570\u636e&#xff0c;\u4f1a\u53d1\u751f\u4e24\u4ef6\u4e92\u4e0d\u914d\u5408\u7684\u4e8b&#xff1a;<\/p>\n<li>transport \u4ecd\u5728\u8bfb\u53d6&#xff0c;data_received() \u7ee7\u7eed\u5f80\u961f\u5217\u8ffd\u52a0\u5b57\u8282\u3002<\/li>\n<li>\u539f\u6765\u7684\u63a5\u6536\u4efb\u52a1\u5df2\u7ecf\u9000\u51fa&#xff0c;\u6ca1\u6709\u4eba\u4ece\u961f\u5217\u91cc\u53d6\u6570\u636e\u3002<\/li>\n<p>read_event.set() \u53ea\u80fd\u901a\u77e5\u201c\u6709\u6570\u636e\u4e86\u201d&#xff0c;\u4e0d\u80fd\u51ed\u7a7a\u627e\u56de\u4e00\u4e2a\u5df2\u7ecf\u53d6\u6d88\u7684\u6d88\u8d39\u8005&#xff0c;\u4e5f\u4e0d\u4f1a\u66ff transport \u6682\u505c\u8bfb\u53d6\u3002\u5e94\u7528\u5982\u679c\u8fdf\u8fdf\u4e0d\u518d\u8c03\u7528 receive()&#xff0c;\u961f\u5217\u5c31\u53ef\u4ee5\u7ee7\u7eed\u589e\u957f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261029103243-6ae320cb14d64.png\" alt=\"\u540c\u4e00\u6b21 receive \u88ab\u53d6\u6d88\u540e\uff0c\u4fee\u590d\u524d\u4fdd\u7559\u8bfb\u53d6\u5f00\u542f\u72b6\u6001\uff0c\u4fee\u590d\u540e\u901a\u8fc7 finally \u6062\u590d\u6682\u505c\" \/><\/p>\n<p>\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u201c\u53d6\u6d88\u6210\u529f\u201d\u4e0e\u201c\u72b6\u6001\u6062\u590d\u6b63\u786e\u201d\u662f\u4e24\u4ef6\u4e8b\u3002\u8fd9\u91cc\u7684\u53d6\u6d88\u5f02\u5e38\u539f\u672c\u5c31\u80fd\u6b63\u5e38\u9000\u51fa\u7b49\u5f85&#xff0c;\u771f\u6b63\u6f0f\u6389\u7684\u662f\u7b49\u5f85\u9000\u51fa\u65f6\u7684\u6536\u5c3e\u3002<\/p>\n<h3>\u4e09\u3001finally \u6536\u56de\u7684\u662f\u8bfb\u53d6\u8bb8\u53ef&#xff0c;\u4e0d\u662f\u8fde\u63a5<\/h3>\n<p>#1424 \u7684\u6700\u7ec8\u6539\u52a8\u628a\u6682\u505c\u653e\u8fdb\u4e86 finally&#xff1a;<\/p>\n<p>self<span class=\"token punctuation\">.<\/span>_transport<span class=\"token punctuation\">.<\/span>resume_reading<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">await<\/span> self<span class=\"token punctuation\">.<\/span>_protocol<span class=\"token punctuation\">.<\/span>read_event<span class=\"token punctuation\">.<\/span>wait<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">finally<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    self<span class=\"token punctuation\">.<\/span>_transport<span class=\"token punctuation\">.<\/span>pause_reading<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u5c31\u628a\u201c\u5f00\u59cb\u7b49\u5f85\u65f6\u542f\u7528\u8bfb\u53d6\u201d\u4e0e\u201c\u79bb\u5f00\u7b49\u5f85\u65f6\u6682\u505c\u8bfb\u53d6\u201d\u914d\u6210\u4e86\u4e00\u5bf9\u3002\u6b63\u5e38\u6536\u5230\u6570\u636e\u8981\u6682\u505c&#xff1b;\u7b49\u5f85\u88ab\u53d6\u6d88&#xff0c;\u4e5f\u8981\u6682\u505c\u3002<\/p>\n<p>\u8fd9\u91cc\u6ca1\u6709\u6355\u83b7\u53d6\u6d88\u5f02\u5e38&#xff0c;\u4e5f\u6ca1\u6709\u8fd4\u56de\u4e00\u4e2a\u5047\u7684\u7a7a\u5b57\u8282\u4e32\u3002finally \u6267\u884c\u5b8c\u540e&#xff0c;\u53d6\u6d88\u4ecd\u4f1a\u7ee7\u7eed\u5411\u5916\u4f20\u64ad&#xff0c;\u7531\u6240\u5c5e\u7684\u53d6\u6d88\u4f5c\u7528\u57df\u5904\u7406\u3002\u6682\u505c\u672c\u8eab\u662f\u540c\u6b65\u8c03\u7528&#xff0c;\u4e0d\u9700\u8981\u518d await \u4e00\u4e2a\u6e05\u7406\u64cd\u4f5c\u3002<\/p>\n<p>\u5b83\u4e5f\u6ca1\u6709\u8c03\u7528 close() \u6216\u6e05\u7a7a\u961f\u5217\u3002\u53d6\u6d88\u4e00\u6b21\u63a5\u6536&#xff0c;\u4e0d\u4ee3\u8868\u5e94\u7528\u653e\u5f03\u6574\u6761\u8fde\u63a5&#xff1b;\u4e0b\u6b21\u518d\u63a5\u6536\u65f6&#xff0c;\u5df2\u6709\u7684\u961f\u5217\u6570\u636e\u4ecd\u7136\u53ef\u4ee5\u53d6\u8d70&#xff0c;\u9700\u8981\u65b0\u6570\u636e\u65f6\u4e5f\u53ef\u4ee5\u91cd\u65b0 resume_reading()\u3002\u5982\u679c\u6570\u636e\u6070\u597d\u5728\u53d6\u6d88\u9644\u8fd1\u5230\u8fbe&#xff0c;\u5df2\u7ecf\u5165\u961f\u7684\u6570\u636e\u4e0d\u8be5\u56e0\u4e3a\u8fd9\u6b21\u53d6\u6d88\u88ab\u987a\u624b\u5220\u6389\u3002<\/p>\n<p>\u8fd9\u6b21\u4fee\u590d\u4fdd\u7559\u4e86\u53d6\u6d88\u3001\u4fdd\u7559\u4e86\u8fde\u63a5&#xff0c;\u4e5f\u4fdd\u7559\u4e86\u5df2\u7ecf\u6536\u5230\u7684\u6570\u636e&#xff1b;\u53ea\u662f\u4e0d\u518d\u8ba9\u9000\u51fa\u7684\u63a5\u6536\u8c03\u7528\u7559\u4e0b\u6301\u7eed\u5f00\u542f\u7684\u8bfb\u53d6\u3002<\/p>\n<h3>\u56db\u3001\u7528\u771f\u5b9e TCP \u8fde\u63a5\u770b\u524d\u540e\u5dee\u522b<\/h3>\n<p>\u8fd9\u7bc7\u914d\u5957\u7684 backpressure_demo \u76f4\u63a5\u52a0\u8f7d\u4e24\u4e2a\u56fa\u5b9a\u63d0\u4ea4\u7684 AnyIO \u6e90\u7801&#xff0c;\u5206\u522b\u5728\u72ec\u7acb\u8fdb\u7a0b\u4e2d\u8fd0\u884c\u540c\u4e00\u6bb5\u5b9e\u9a8c&#xff1a;<\/p>\n<ul>\n<li>\u4fee\u590d\u524d&#xff1a;633965b&#xff0c;\u5408\u5e76\u63d0\u4ea4\u7684\u7236\u63d0\u4ea4\u3002<\/li>\n<li>\u4fee\u590d\u540e&#xff1a;6219807&#xff0c;\u6700\u7ec8\u5408\u5e76\u63d0\u4ea4\u3002<\/li>\n<\/ul>\n<p>\u5b9e\u9a8c\u5728\u672c\u673a\u7684 IPv4 \u56de\u73af TCP \u8fde\u63a5\u4e0a\u8fdb\u884c\u3002\u5148\u8ba9\u63a5\u6536\u4efb\u52a1\u771f\u6b63\u8fdb\u5165\u7b49\u5f85&#xff0c;\u786e\u8ba4 transport \u5df2\u5f00\u542f\u8bfb\u53d6&#xff0c;\u518d\u53d6\u6d88\u5b83\u3002\u7b49\u63a5\u6536\u4efb\u52a1\u9000\u51fa\u540e&#xff0c;\u5bf9\u7aef\u5f00\u59cb\u53d1\u9001 4 MiB \u6570\u636e&#xff1b;\u63a5\u6536\u7aef\u6682\u65f6\u4e0d\u518d\u8c03\u7528 receive()&#xff0c;\u89c2\u5bdf 0.3 \u79d2\u3002\u968f\u540e\u6062\u590d\u63a5\u6536&#xff0c;\u9010\u5b57\u8282\u6838\u5bf9\u5185\u5bb9&#xff0c;\u5e76\u7ee7\u7eed\u7528\u540c\u4e00\u6761\u8fde\u63a5\u4f20\u8f93\u4e00\u6bb5\u65b0\u6570\u636e\u3002<\/p>\n<p>\u5728 Windows 11\u3001CPython 3.12.14\u3001\u9ed8\u8ba4 ProactorEventLoop \u4e0b&#xff0c;\u7ed3\u679c\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u89c2\u5bdf\u9879\u4fee\u590d\u524d\u4fee\u590d\u540e<\/tr>\n<tbody>\n<tr>\n<td>\u53d6\u6d88\u7ed3\u675f\u540e\u7684 transport.is_reading()<\/td>\n<td align=\"right\">True<\/td>\n<td align=\"right\">False<\/td>\n<\/tr>\n<tr>\n<td>0.3 \u79d2\u540e read_queue \u4e2d\u7684\u5b57\u8282\u6570<\/td>\n<td align=\"right\">4,194,304&#xff08;4 MiB&#xff09;<\/td>\n<td align=\"right\">0<\/td>\n<\/tr>\n<tr>\n<td>\u6062\u590d\u63a5\u6536\u540e\u5f97\u5230\u7684\u6570\u636e<\/td>\n<td align=\"right\">4 MiB&#xff0c;\u5185\u5bb9\u4e00\u81f4<\/td>\n<td align=\"right\">4 MiB&#xff0c;\u5185\u5bb9\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>\u540c\u4e00\u8fde\u63a5\u7ee7\u7eed\u53cc\u5411\u6536\u53d1<\/td>\n<td align=\"right\">\u6b63\u5e38<\/td>\n<td align=\"right\">\u6b63\u5e38<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u65e7\u7248\u628a\u5168\u90e8 4 MiB \u90fd\u642c\u8fdb\u4e86 Python \u961f\u5217\u3002\u4fee\u590d\u7248\u6ca1\u6709\u7ee7\u7eed\u5411\u8fd9\u4e2a\u961f\u5217\u4ea4\u4ed8\u6570\u636e&#xff0c;\u4f46\u6570\u636e\u4e5f\u6ca1\u4e22&#xff1a;\u91cd\u65b0\u63a5\u6536\u540e&#xff0c;4 MiB \u5b8c\u6574\u5230\u8fbe&#xff0c;\u8fde\u63a5\u8fd8\u80fd\u7ee7\u7eed\u7528\u3002<\/p>\n<p>\u4e24\u7248\u5728\u8fd9\u4e2a\u89c2\u5bdf\u70b9\u4e0a&#xff0c;\u53d1\u9001\u4efb\u52a1\u90fd\u5df2\u7ecf\u5b8c\u6210\u3002\u8fd9\u6070\u597d\u80fd\u628a\u4e24\u4e2a\u6982\u5ff5\u5206\u5f00&#xff1a;\u6570\u636e\u53ef\u4ee5\u5148\u88ab\u7cfb\u7edf\u7f13\u51b2\u63a5\u4f4f&#xff0c;\u5e76\u4e0d\u610f\u5473\u7740\u5b83\u5df2\u7ecf\u8fdb\u5165 AnyIO \u7684 Python \u961f\u5217&#xff1b;\u4fee\u590d\u6062\u590d\u4e86\u8bfb\u53d6\u4fa7\u7684\u80cc\u538b&#xff0c;\u4e0d\u662f\u5f3a\u8feb\u5bf9\u7aef\u6bcf\u6b21\u53d1\u9001\u90fd\u7acb\u5373\u7b49\u5f85\u3002<\/p>\n<p>\u914d\u5957\u5de5\u7a0b\u5728\u9ed8\u8ba4\u5faa\u73af\u4e0e Windows Selector \u5faa\u73af\u4e0b&#xff0c;\u5404\u5bf9\u4e24\u7248\u590d\u8dd1 10 \u6b21&#xff0c;\u961f\u5217\u5feb\u7167\u90fd\u662f\u4e0a\u8868\u7684 4 MiB \/ 0&#xff0c;\u53d6\u6d88\u4f20\u64ad\u3001\u6570\u636e\u5b8c\u6574\u6027\u548c\u8fde\u63a5\u590d\u7528\u68c0\u67e5\u5747\u901a\u8fc7\u3002\u8fdb\u5165 backpressure_demo \u76ee\u5f55\u540e\u53ef\u4ee5\u8fd0\u884c&#xff1a;<\/p>\n<p>python <span class=\"token operator\">&#8211;<\/span>m pip install <span class=\"token operator\">&#8211;<\/span>r requirements<span class=\"token punctuation\">.<\/span>txt<br \/>\npython run<span class=\"token punctuation\">.<\/span>py <span class=\"token operator\">&#8212;<\/span>test<\/p>\n<p>\u9996\u6b21\u8fd0\u884c\u4f1a\u4e0b\u8f7d\u4e24\u4efd\u56fa\u5b9a\u6e90\u7801&#xff0c;\u4ee5\u540e\u53ef\u4ee5\u52a0 &#8211;offline \u4f7f\u7528\u7f13\u5b58\u3002&#8211;test \u5bf9\u4e24\u7248\u5404\u8dd1 3 \u9879\u96c6\u6210\u6d4b\u8bd5&#xff1a;\u65e7\u7248\u901a\u8fc7\u8868\u793a\u6210\u529f\u590d\u73b0\u4e86\u9519\u8bef\u72b6\u6001&#xff0c;\u4fee\u590d\u7248\u901a\u8fc7\u624d\u8868\u793a\u8bfb\u53d6\u5df2\u6062\u590d\u6682\u505c\u3002<\/p>\n<p>\u8fd9\u91cc\u68c0\u67e5\u7684\u7f13\u51b2\u5b57\u8282\u6570\u662f sum(len(chunk) for chunk in stream._protocol.read_queue)&#xff0c;\u4e0d\u662f\u8fdb\u7a0b RSS&#xff0c;\u4e5f\u4e0d\u5305\u542b\u5185\u6838\u7f13\u51b2\u6216 transport \u5185\u90e8\u53ef\u80fd\u6682\u5b58\u7684\u6570\u636e\u3002\u79c1\u6709\u5c5e\u6027\u53ea\u7528\u6765\u89c2\u5bdf\u8fd9\u4e2a\u56fa\u5b9a\u7248\u672c\u7684\u5b9e\u73b0\u3002<\/p>\n<p>4 MiB \u662f\u5b9e\u9a8c\u9009\u62e9\u7684\u53d1\u9001\u91cf&#xff0c;\u4e0d\u662f\u6f0f\u6d1e\u7684\u4e0a\u9650\u30020.3 \u79d2\u4e5f\u662f\u89c2\u5bdf\u7a97\u53e3&#xff0c;\u4e0d\u662f\u541e\u5410\u91cf\u6d4b\u8bd5&#xff1a;\u6362\u4e00\u4e2a\u4e8b\u4ef6\u5faa\u73af\u3001\u64cd\u4f5c\u7cfb\u7edf\u6216\u8d1f\u8f7d&#xff0c;\u7a97\u53e3\u5185\u5230\u8fbe\u7684\u5b57\u8282\u6570\u53ef\u4ee5\u4e0d\u540c\u3002\u5173\u952e\u7684\u72b6\u6001\u5bf9\u7167\u662f&#xff0c;\u53d6\u6d88\u7ed3\u675f\u540e transport \u662f\u5426\u8fd8\u5728\u8bfb&#xff0c;\u4ee5\u53ca\u6062\u590d\u63a5\u6536\u540e\u6570\u636e\u80fd\u5426\u5b8c\u6574\u4ea4\u4ed8\u3002<\/p>\n<h3>\u4e94\u3001TLS \u4e3a\u4ec0\u4e48\u4e5f\u4f1a\u7ecf\u8fc7\u8fd9\u6761\u8def\u5f84<\/h3>\n<p>\u7ed9\u8fde\u63a5\u52a0\u4e0a TLS&#xff0c;\u5e76\u4e0d\u4f1a\u8ba9\u5e95\u5c42 TCP \u7684\u8bfb\u53d6\u72b6\u6001\u81ea\u52a8\u6062\u590d\u3002<\/p>\n<p>AnyIO \u7684 TLSStream.receive() \u5c1d\u8bd5\u4ece SSL \u5bf9\u8c61\u4e2d\u53d6\u51fa\u660e\u6587\u3002SSL \u5bf9\u8c61\u9700\u8981\u66f4\u591a\u7f51\u7edc\u6570\u636e\u65f6&#xff0c;_call_sslobject_method() \u4f1a\u8d70\u5230\u8fd9\u53e5&#xff08;\u6e90\u7801&#xff09;&#xff1a;<\/p>\n<p>data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> self<span class=\"token punctuation\">.<\/span>transport_stream<span class=\"token punctuation\">.<\/span>receive<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5f53 transport_stream \u5c31\u662f asyncio \u540e\u7aef\u7684 TCP SocketStream&#xff0c;\u7b49\u5f85\u4fbf\u843d\u56de\u4e0a\u9762\u540c\u4e00\u4e2a receive()\u3002\u5728\u8fd9\u91cc\u88ab\u53d6\u6d88&#xff0c;\u540c\u6837\u53ef\u80fd\u8df3\u8fc7\u65e7\u4ee3\u7801\u7684\u6682\u505c\u3002\u4e4b\u540e\u7ee7\u7eed\u8fdb\u5165\u5e95\u5c42\u961f\u5217\u7684\u662f TLS \u5bc6\u6587\u5b57\u8282&#xff0c;\u4e0d\u8981\u6c42\u4e0a\u5c42\u4ecd\u5728\u89e3\u5bc6\u6216\u6d88\u8d39\u660e\u6587\u3002<\/p>\n<p>TLS \u8d1f\u8d23\u52a0\u5bc6\u548c\u89e3\u5bc6&#xff0c;\u4e0d\u4f1a\u66ff\u5e95\u5c42\u63a5\u6536\u961f\u5217\u8865\u4e0a\u9057\u6f0f\u7684\u80cc\u538b\u3002\u8fd9\u4e00\u6bb5\u8bf4\u660e\u7684\u662f\u5171\u4eab\u7684\u8c03\u7528\u8def\u5f84&#xff1b;\u524d\u9762\u7684 4 MiB \u5b9e\u6d4b\u8dd1\u7684\u662f\u666e\u901a TCP\u3002<\/p>\n<h3>\u516d\u3001\u56de\u5f52\u6d4b\u8bd5\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u4e0d\u53d1\u90a3 4 MiB<\/h3>\n<p>\u771f\u5b9e\u8fde\u63a5\u91cc\u7684\u961f\u5217\u589e\u957f\u80fd\u8bf4\u660e\u540e\u679c&#xff0c;\u4f46\u8981\u9632\u6b62\u8fd9\u6b21\u9519\u8bef\u91cd\u6765&#xff0c;\u6d4b\u8bd5\u53ef\u4ee5\u66f4\u76f4\u63a5\u3002<\/p>\n<p>PR \u6700\u7ec8\u5408\u5e76\u7684\u56de\u5f52\u6d4b\u8bd5\u6ca1\u6709\u9760\u6301\u7eed\u704c\u6570\u636e\u3001\u89c2\u5bdf\u5185\u5b58\u4e0a\u6da8\u6765\u5224\u65ad\u3002\u5b83\u5efa\u7acb\u4e00\u6761 TCP \u8fde\u63a5&#xff0c;\u5728\u5df2\u7ecf\u53d6\u6d88\u7684\u4f5c\u7528\u57df\u91cc\u8c03\u7528\u4e00\u6b21 receive()&#xff0c;\u9000\u51fa\u540e\u76f4\u63a5\u68c0\u67e5 transport \u72b6\u6001&#xff08;\u4e0a\u6e38\u6d4b\u8bd5&#xff0c;\u8282\u9009&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> <span class=\"token keyword\">await<\/span> connect_tcp<span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span>server_addr<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> stream<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">with<\/span> CancelScope<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> scope<span class=\"token punctuation\">:<\/span><br \/>\n        scope<span class=\"token punctuation\">.<\/span>cancel<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">await<\/span> stream<span class=\"token punctuation\">.<\/span>receive<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">assert<\/span> <span class=\"token keyword\">not<\/span> stream<span class=\"token punctuation\">.<\/span>_transport<span class=\"token punctuation\">.<\/span>is_reading<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5148 scope.cancel()&#xff0c;\u5e76\u4e0d\u610f\u5473\u7740\u540e\u9762\u7684 Python \u8bed\u53e5\u5c31\u4e0d\u6267\u884c\u4e86\u3002\u5bf9\u4e8e\u8fd9\u6761\u8fd8\u6ca1\u6709\u6570\u636e\u7684\u8fde\u63a5&#xff0c;receive() \u4ecd\u4f1a\u8d70\u5230 resume_reading()&#xff0c;\u968f\u540e\u5728\u7b49\u5f85\u70b9\u6536\u5230\u53d6\u6d88&#xff1b;\u65e7\u4ee3\u7801\u8df3\u8fc7\u6682\u505c&#xff0c;\u65b0\u4ee3\u7801\u8fdb\u5165 finally\u3002\u8fd9\u4e2a\u77ed\u6d4b\u8bd5\u6b63\u597d\u5361\u4f4f\u4e24\u7248\u5206\u53c9\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u8fd9\u4e2a\u5199\u6cd5\u6765\u81ea\u7ef4\u62a4\u8005\u5728 review \u4e2d\u7684\u5efa\u8bae\u3002\u5b83\u4e0d\u5fc5\u8bc1\u660e\u6574\u4e2a TCP \u6d41\u91cf\u63a7\u5236\u8fc7\u7a0b&#xff0c;\u53ea\u8981\u9489\u4f4f\u672c\u6b21\u9519\u8bef\u7684\u76f4\u63a5\u539f\u56e0&#xff1a;\u53d6\u6d88\u63a5\u6536\u4e4b\u540e&#xff0c;\u8bfb\u53d6\u4e0d\u5e94\u8be5\u8fd8\u5f00\u7740\u3002\u81f3\u4e8e\u5b9e\u9645\u963b\u585e\u540e\u518d\u53d6\u6d88\u3001\u961f\u5217\u589e\u957f\u548c\u8fde\u63a5\u80fd\u5426\u7ee7\u7eed\u4f7f\u7528&#xff0c;\u5219\u7531\u914d\u5957\u590d\u73b0\u5c55\u5f00\u89c2\u5bdf\u3002<\/p>\n<h3>\u5199\u5728\u6700\u540e<\/h3>\n<p>\u8fd9\u6b21\u9519\u8bef\u4e0d\u5728\u201c\u53d6\u6d88\u6709\u6ca1\u6709\u5230\u8fbe\u201d&#xff0c;\u800c\u5728\u201c\u5230\u8fbe\u4ee5\u540e&#xff0c;\u8c01\u6765\u6062\u590d\u7b49\u5f85\u4e4b\u524d\u6539\u8fc7\u7684\u72b6\u6001\u201d\u3002<\/p>\n<p>resume_reading() \u5e76\u6ca1\u6709\u56e0\u4e3a\u63a5\u6536\u4efb\u52a1\u7ed3\u675f\u5c31\u81ea\u52a8\u5931\u6548\u3002\u5b83\u6539\u53d8\u7684\u662f\u53e6\u4e00\u4e2a\u5bf9\u8c61\u2014\u2014transport\u2014\u2014\u7684\u6301\u4e45\u72b6\u6001\u3002\u628a pause_reading() \u5199\u5728 await \u7684\u4e0b\u4e00\u884c&#xff0c;\u53ea\u7167\u987e\u4e86\u6b63\u5e38\u8fd4\u56de&#xff1b;\u653e\u8fdb finally&#xff0c;\u624d\u8ba9\u8fd9\u6b21\u63a5\u6536\u4e34\u65f6\u5f00\u542f\u7684\u8bfb\u53d6&#xff0c;\u968f\u7740\u8fd9\u6b21\u7b49\u5f85\u4e00\u8d77\u7ed3\u675f\u3002<\/p>\n<p>\u539f\u59cb\u95ee\u9898\u4e0e\u590d\u73b0\u89c1 #1423&#xff0c;\u4fee\u590d\u4e0e\u8ba8\u8bba\u89c1 #1424\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4e00\u6b21\u7f51\u7edc\u63a5\u6536\u52a0\u4e0a\u8d85\u65f6&#xff0c;\u8d85\u65f6\u4e4b\u540e\u53bb\u505a\u522b\u7684\u4e8b&#xff0c;\u8fde\u63a5\u7559\u7740\u4e0b\u6b21\u518d\u7528\u3002\u8fd9\u662f\u5f88\u5e73\u5e38\u7684\u5199\u6cd5&#xff1a;<br \/>\nwith anyio.move_on_after(0.1):data  await stream.receive()# \u6682\u65f6\u4e0d\u518d\u63a5\u6536&#xff0c;\u4f46\u4fdd\u7559\u8fd9\u6761\u8fde\u63a5\u5728\u4fee\u590d\u524d\u7684 AnyIO asyncio \u540e\u7aef\u91cc&#xff0c;\u8fd9\u91cc\u4f1a\u7559\u4e0b\u4e00\u4e2a\u4e0d\u592a\u663e\u773c\u7684\u72b6\u6001&#xff1a;receive() \u5df2\u7ecf\u56e0\u8d85\u65f6\u9000\u51fa&#xff0c;\u5e95\u5c42 TCP transport \u5374<\/p>\n","protected":false},"author":2,"featured_media":119456,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,205,78,191],"topic":[],"class_list":["post-119457","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-tcp-ip","tag-78","tag-191"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d - \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\/119457.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7ed9\u4e00\u6b21\u7f51\u7edc\u63a5\u6536\u52a0\u4e0a\u8d85\u65f6&#xff0c;\u8d85\u65f6\u4e4b\u540e\u53bb\u505a\u522b\u7684\u4e8b&#xff0c;\u8fde\u63a5\u7559\u7740\u4e0b\u6b21\u518d\u7528\u3002\u8fd9\u662f\u5f88\u5e73\u5e38\u7684\u5199\u6cd5&#xff1a; with anyio.move_on_after(0.1):data await stream.receive()# \u6682\u65f6\u4e0d\u518d\u63a5\u6536&#xff0c;\u4f46\u4fdd\u7559\u8fd9\u6761\u8fde\u63a5\u5728\u4fee\u590d\u524d\u7684 AnyIO asyncio \u540e\u7aef\u91cc&#xff0c;\u8fd9\u91cc\u4f1a\u7559\u4e0b\u4e00\u4e2a\u4e0d\u592a\u663e\u773c\u7684\u72b6\u6001&#xff1a;receive() \u5df2\u7ecf\u56e0\u8d85\u65f6\u9000\u51fa&#xff0c;\u5e95\u5c42 TCP transport \u5374\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/119457.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-29T10:32:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261029103243-6ae320cb14d64.png\" \/>\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\/119457.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/119457.html\",\"name\":\"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-29T10:32:45+00:00\",\"dateModified\":\"2026-10-29T10:32:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/119457.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/119457.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119457.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d\"}]},{\"@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":"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d - \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\/119457.html","og_locale":"zh_CN","og_type":"article","og_title":"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7ed9\u4e00\u6b21\u7f51\u7edc\u63a5\u6536\u52a0\u4e0a\u8d85\u65f6&#xff0c;\u8d85\u65f6\u4e4b\u540e\u53bb\u505a\u522b\u7684\u4e8b&#xff0c;\u8fde\u63a5\u7559\u7740\u4e0b\u6b21\u518d\u7528\u3002\u8fd9\u662f\u5f88\u5e73\u5e38\u7684\u5199\u6cd5&#xff1a; with anyio.move_on_after(0.1):data await stream.receive()# \u6682\u65f6\u4e0d\u518d\u63a5\u6536&#xff0c;\u4f46\u4fdd\u7559\u8fd9\u6761\u8fde\u63a5\u5728\u4fee\u590d\u524d\u7684 AnyIO asyncio \u540e\u7aef\u91cc&#xff0c;\u8fd9\u91cc\u4f1a\u7559\u4e0b\u4e00\u4e2a\u4e0d\u592a\u663e\u773c\u7684\u72b6\u6001&#xff1a;receive() \u5df2\u7ecf\u56e0\u8d85\u65f6\u9000\u51fa&#xff0c;\u5e95\u5c42 TCP transport \u5374","og_url":"https:\/\/www.wsisp.com\/helps\/119457.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-29T10:32:45+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261029103243-6ae320cb14d64.png"}],"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\/119457.html","url":"https:\/\/www.wsisp.com\/helps\/119457.html","name":"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-29T10:32:45+00:00","dateModified":"2026-10-29T10:32:45+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/119457.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/119457.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/119457.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"receive \u53d6\u6d88\u4e86\uff0cTCP \u4e3a\u4ec0\u4e48\u8fd8\u5728\u8bfb\uff1aAnyIO \u7684\u4e00\u6b21\u80cc\u538b\u4fee\u590d"}]},{"@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\/119457","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=119457"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119457\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/119456"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=119457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=119457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=119457"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=119457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}