{"id":419715,"date":"2021-03-31T19:08:15","date_gmt":"2021-03-31T11:08:15","guid":{"rendered":"http:\/\/4563.org\/?p=419715"},"modified":"2021-03-31T19:08:15","modified_gmt":"2021-03-31T11:08:15","slug":"%e6%8a%80%e6%9c%af%e6%8f%ad%e7%a7%98-%e7%90%86%e8%a7%a3-asyncio-%e6%9d%a5%e6%9e%84%e5%bb%ba%e9%ab%98%e6%80%a7%e8%83%bd-python-%e7%bd%91%e7%bb%9c%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=419715","title":{"rendered":"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : thinkingmind <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Python \u662f\u4e00\u95e8\u4e0a\u624b\u5feb\u3001\u4f18\u96c5\u7b80\u6d01\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5176\u591a\u8303\u5f0f\u3001\u4e30\u5bcc\u7684\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\u80fd\u591f\u8ba9\u7f16\u7a0b\u4eba\u5458\u628a\u7cbe\u529b\u96c6\u4e2d\u5728\u903b\u8f91\u548c\u601d\u7ef4\u65b9\u6cd5\u4e0a\uff0c\u800c\u4e0d\u7528\u53bb\u62c5\u5fc3\u590d\u6742\u8bed\u6cd5\u3001\u7c7b\u578b\u7cfb\u7edf\u7b49\u5916\u5728\u56e0\u7d20\uff0c\u4ece\u800c\u9ad8\u6548\u5730\u8fbe\u6210\u81ea\u5df1\u7684\u7f16\u7a0b\u76ee\u6807\u3002Python \u62bd\u8c61\u5c42\u6b21\u975e\u5e38\u9ad8\uff0c\u8fd9\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u66f4\u5feb\u5730\u5b8c\u6210\u7f16\u7a0b\uff0c\u4f46\u4e5f\u5c4f\u853d\u4e86\u5f88\u591a\u7ec6\u8282\uff0c\u7a0b\u5e8f\u5458\u4e5f\u65e0\u6cd5\u7cbe\u786e\u63a7\u5236\u8ba1\u7b97\u673a\u5e95\u5c42\u7684\u8d44\u6e90\uff0c\u4ee3\u7801\u6027\u80fd\u4f18\u5316\u5c31\u53d8\u5f97\u6bd4\u8f83\u590d\u6742\u3002\u5f88\u591a\u8d44\u6df1\u7684\u7a0b\u5e8f\u5458\u53ef\u80fd\u4f1a\u89c9\u5f97 Python \u6027\u80fd\u4e0d\u591f\u597d\uff0c\u65e0\u6cd5\u7f16\u5199\u9ad8\u6027\u80fd\u7684\u7a0b\u5e8f\uff0c\u5176\u5b9e\u8fd9\u53e5\u8bdd\u4e5f\u4e0d\u5168\u5bf9\u3002\u5bf9\u4e8e\u8ba1\u7b97\u5bc6\u96c6\u578b\u7684\u7a0b\u5e8f\uff0cPython \u53ef\u4ee5<strong>\u901a\u8fc7\u6269\u5c55\u7684\u5f62\u5f0f\u4f7f\u5f97\u6838\u5fc3\u8ba1\u7b97\u76f4\u63a5\u8c03\u7528\u5176\u5b83\u8bed\u8a00\uff08\u901a\u5e38\u662f C \u8bed\u8a00\uff09\u5199\u7684\u5305<\/strong>\u3002\u6bd4\u5982\u8bf4\u8fd1\u671f\u6d41\u884c\u7684\u673a\u5668\u5b66\u4e60\u6240\u4f7f\u7528\u7684 CUDA \u6280\u672f\uff0cNvidia \u5c31\u5728\u5b98\u7f51\u53d1\u8868\u4e86\u4e00\u7bc7\u6587\u7ae0\u4e13\u95e8\u8bb2\u5982\u4f55\u901a\u8fc7 Python \u4f7f\u7528 CUDA \u6280\u672f\u3002\u8fd8\u6709\u79d1\u5b66\u8ba1\u7b97\u5e93 Numpy\uff0c\u4e5f\u662f\u6709\u4ee3\u8868\u7684 Python \u9ad8\u6027\u80fd\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u5982\u679c\u7b2c\u4e09\u65b9\u5e93\u4e0d\u80fd\u6ee1\u8db3\u6211\u4eec\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7 Cython \u8fd9\u79cd\u6709\u7740\u7c7b Python \u8bed\u6cd5\u7684\u5de5\u5177\u6765\u751f\u6210 Python \u7684 C \u8bed\u8a00\u6269\u5c55\u5e93\uff0c\u76f4\u63a5\u7ed9\u6211\u4eec\u7684\u7a0b\u5e8f\u52a0\u901f\u3002\u8fd9\u4e9b\u6280\u672f\u4f7f\u5f97 Python \u4e5f\u53ef\u4ee5\u6709\u9ad8\u6027\u80fd\u7684\u8ba1\u7b97\u80fd\u529b\uff0c\u4f46\u662f\u672c\u8eab\u6838\u5fc3\u4ee3\u7801\u5e76\u4e0d\u662f\u7528 Python \u5199\u7684\uff0c\u6240\u4ee5\u5728\u672c\u6587\u4e2d\u4e0d\u5173\u6ce8\u8fd9\u4e9b\u6280\u672f\u3002\u6211\u4eec\u5728\u672c\u6587\u4e2d\u4e3b\u8981\u8ba8\u8bba\u53e6\u4e00\u79cd\u60c5\u51b5\uff0c<strong>\u5982\u4f55\u5199 I\/O \u5bc6\u96c6\u578b\u7684\u9ad8\u6027\u80fd Python \u7a0b\u5e8f<\/strong>\u3002<\/p>\n<p>RQData \u5c31\u662f\u4e00\u4e2a<strong>\u5178\u578b\u7684\u9700\u8981\u9ad8 I\/O \u6027\u80fd\u7684\u4ea7\u54c1\u3002<\/strong>RQData \u662f\u7c73\u7b50\u4e3a\u4e13\u4e1a\u6295\u8d44\u8005\u63d0\u4f9b\u4fbf\u5229\u6613\u7528\u7684\u91d1\u878d\u6570\u636e API \u3002\u7528\u6237<strong>\u4f7f\u7528 RQData \u5ba2\u6237\u7aef\u5de5\u5177\u5305 rqdatac\uff0c\u901a\u8fc7\u7f51\u7edc\u7684\u65b9\u5f0f\u8c03\u53d6\u5b58\u5728\u8fdc\u7a0b\u7684\u91d1\u878d\u6570\u636e<\/strong>\uff08\u4e91\u7aef\u6216\u672c\u5730\u53d6\u51b3\u4e8e\u5b9e\u65bd\u65b9\u5f0f\uff09\u3002RQData \u63d0\u4f9b\u4e86\u975e\u5e38\u591a\u7684 Python API\uff0c\u65b9\u4fbf\u6295\u8d44\u8005\u8c03\u53d6\u5168\u5e02\u573a\u7684\u91d1\u878d\u6570\u636e\u3002\u8fd9\u4e9b API \u5305\u542b\u4e86\u80a1\u7968\u3001\u671f\u8d27\u3001\u73b0\u8d27\u3001\u671f\u6743\u3001\u53ef\u8f6c\u503a\u3001\u573a\u5185\u57fa\u91d1\u3001\u98ce\u9669\u56e0\u5b50\u3001\u8d22\u52a1\u56e0\u5b50\u7b49\u7c7b\u578b\uff0c\u800c\u8fd9\u4e9b\u6570\u636e\u6700\u91cd\u8981\u7684\u7279\u6027\u5c31\u662f<strong>\u6570\u636e\u91cf\u5927<\/strong>\u3002RQData \u65e5\u5e38\u9762\u4e34\u7740<strong>\u6bcf\u5929\u6570\u4ebf\u6b21<\/strong>\u5bf9\u4e8e\u603b\u91cf\u7ea6\u4e3a <strong>1T \u6570\u636e<\/strong>\u7684\u968f\u673a\u8c03\u53d6\u3002\u8fd9\u4e9b\u8c03\u53d6\u6240\u9700\u8fd4\u56de\u7684\u6570\u636e\u91cf\u5f80\u5f80\u4e5f\u76f8\u5f53\u5e9e\u5927\uff0c\u4f8b\u5982\u5341\u5e74\u5168 A \u80a1\u7684\u65e5\u7ebf\u6570\u636e\u5927\u7ea6\u4f1a\u8fd4\u56de 1 \u4e2a G \u7684\u6570\u636e\u3002\u5728\u8fd9\u6837\u7684\u538b\u529b\u4e0b\uff0c\u6211\u4eec\u4ecd\u5e0c\u671b\u7528\u6237\u5728\u4f7f\u7528 RQData \u7684\u65f6\u5019\u5c31\u50cf\u6d4f\u89c8\u5668\u4e0b\u8f7d\u6587\u4ef6\u4e00\u6837\u5feb\uff0c\u8fd9\u4e9b\u9700\u6c42\u5728 RQData \u4e2d\u90fd\u662f<strong>\u7528 Python \u901a\u8fc7<\/strong> <strong>asyncio<\/strong> <strong>\u6a21\u5757<\/strong>\u5b8c\u6210\u7684\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u4e00\u8d77\u7531\u6d45\u5165\u6df1\u5730\u5b66\u4e60\u4e00\u4e0b asyncio \u3002<\/p>\n<h1><strong>Asyncio \u521d\u8bc6<\/strong><\/h1>\n<p> <\/p>\n<p>asyncio \u662f Python 3.5 \u4e2d\u5f15\u5165\u7684\u4e00\u4e2a\u5e93, \u76ee\u7684\u662f<strong>\u65b9\u4fbf\u7f16\u5199\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f<\/strong>\u3002\u4e00\u4e2a\u7b80\u5355\u7684\u4ee5 RQData \u670d\u52a1\u7aef\u4e3a\u4f8b\u7684\u7f51\u7edc\u5904\u7406\u7684\u6838\u5fc3\u4ee3\u7801\u57fa\u672c\u5982\u4e0b\uff08\u7b80\u5316\u4e86 API \u7684\u4e1a\u52a1\u903b\u8f91\uff09\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d32cf3571.jpg\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5efa\u6784\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u670d\u52a1\u7aef\u5e94\u7528\uff0c\u5b83<strong>\u63a5\u6536\u5230\u7528\u6237\u7684\u8fde\u63a5\u540e\uff0c\u76f4\u63a5\u8fd4\u56de\u7528\u6237\u8f93\u5165\u7684\u6570\u636e<\/strong>\u3002\u8fd9\u4e2a\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\uff0c\u5374\u80fd\u4f53\u73b0\u51fa asyncio \u7684\u9b45\u529b\u3002\u6211\u4eec\u6784\u5efa\u7684\u7a0b\u5e8f\u975e\u5e38\u50cf\u4f20\u7edf\u7684\u7f51\u7edc\u7a0b\u5e8f\u3002\u548c\u4f20\u7edf\u7684\u7f51\u7edc\u7a0b\u5e8f\u76f8\u6bd4\uff0c\u6211\u4eec\u6539\u52a8\u4e86<strong>\u4e09\u5904<\/strong>\uff1a<\/p>\n<ul>\n<li>\u7528\u4e86 async \u5173\u952e\u5b57\u5b9a\u4e49\u4e86\u4e00\u4e2a\u534f\u7a0b\u51fd\u6570\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u666e\u901a\u7684\u51fd\u6570\u3002<\/li>\n<li>\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684\u963b\u585e\u7684\u51fd\u6570\u8c03\u7528 , \u5728\u8c03\u7528 async \u5173\u952e\u5b57\u5b9a\u4e49\u7684\u51fd\u6570\u524d\u52a0\u5165\u4e86 await \u3002<\/li>\n<li>\u6ca1\u6709\u4f7f\u7528 socket \u5b9a\u4e49\u7684\u65b9\u6cd5\uff0c\u800c\u662f\u6362\u6210\u4e86 asyncio \u4e2d EventLoop \u5b9a\u4e49\u7684 async \u534f\u7a0b\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p>\u4ec5\u4ec5\u591a\u4e86 async \u548c await \u4e24\u4e2a\u5173\u952e\u5b57\uff0c\u6211\u4eec\u5c31\u4eab\u53d7\u4e86\u534f\u7a0b\u7684\u4f18\u52bf\u3002\u534f\u7a0b\u8ba9\u6211\u4eec\u4e0d\u7528\u62c5\u5fc3\u8fc7\u591a\u7684\u7ebf\u7a0b\u5bfc\u81f4\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\u5360\u7528\u4e86\u592a\u591a\u7684 CPU \u65f6\u95f4\uff0c\u6211\u4eec\u7684\u7a0b\u5e8f\u53ef\u4ee5\u8fd0\u884c\u5728\u4e00\u4e2a CPU \u4e0a\uff0c\u4eab\u53d7 CPU \u7684\u9ad8\u901f\u7f13\u5b58\uff0c\u51cf\u5c11 CPU \u7f13\u5b58\u540c\u6b65\u7684\u5f00\u9500\uff0c\u800c\u4e14\u6211\u4eec\u7684\u4ee3\u7801\u975e\u5e38\u5bb9\u6613\u7406\u89e3\uff0c\u51e0\u4e4e\u548c\u4f20\u7edf\u7684\u7f51\u7edc\u7a0b\u5e8f\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\u3002<\/p>\n<h1><strong>\u5f02\u6b65\u4e0e\u534f\u7a0b<\/strong><\/h1>\n<p> <\/p>\n<p><strong>asyncio<\/strong> <strong>\u5168\u79f0 asynchronous I\/O \u2014\u2014\u5f02\u6b65\u8f93\u5165\u8f93\u51fa<\/strong>\u3002\u76f8\u5bf9\u4e8e\u540c\u6b65\uff0c\u5f02\u6b65\u51fd\u6570\u4f1a\u5728\u8c03\u7528\u65f6\u4e0d\u7b49\u5f85 I\/O \u64cd\u4f5c\u5b8c\u6210\uff0cI\/O \u7ed3\u679c\u901a\u8fc7\u56de\u8c03\u7684\u65b9\u5f0f\u4ea4\u7ed9\u8c03\u7528\u8005\u3002\u4e3e\u4e2a\u6253\u7535\u8bdd\u7684\u4f8b\u5b50\uff0c\u5982\u679c\u5bf9\u65b9\u5fd9\u7ebf\uff0c\u540c\u6b65\u51fd\u6570\u4f1a\u4e00\u8d77\u6302\u8d77\uff0c\u76f4\u5230\u5bf9\u65b9\u63a5\u542c\u4e86\u6211\u7684\u7535\u8bdd\uff1b\u5f02\u6b65\u51fd\u6570\u5219\u662f\u7559\u8a00\u5230\u8bed\u97f3\u4fe1\u7bb1\uff0c\u901a\u77e5\u5bf9\u65b9\u5728\u5b8c\u6210\u4e86\u4e0a\u4e00\u901a\u7535\u8bdd\u540e\uff0c\u518d\u7ed9\u6211\u56de\u7535\u3002<\/p>\n<p>\u867d\u7136 Python \u5728 3.5 \u7248\u672c\u4e2d\u624d\u5f15\u5165\u534f\u7a0b\uff0c\u4f46\u5176\u5b9e\u534f\u7a0b\u7684\u5386\u53f2\u975e\u5e38\u4e45\u8fdc\u3002\u6700\u65e9\u5bf9\u534f\u7a0b\u7684\u4e66\u9762\u89e3\u8bf4\u53ef\u8ffd\u6eaf\u5230 1963 \u5e74\u9a6c\u5c14\u6587 \u00b7 \u7231\u5fb7\u534e \u00b7 \u5eb7\u5a01\uff08 MelvinE.Conway \uff09\u5199\u7684\u4e00\u7bc7\u5173\u4e8e\u5982\u4f55\u5199 COBOL \u8bed\u8a00\u7f16\u8bd1\u5668\u7684\u6587\u7ae0\u3002\u8fd9\u7bc7\u6587\u7ae0\u6307\u51fa\u53ef\u4ee5\u57fa\u4e8e\u72b6\u6001\u673a\u548c\u534f\u7a0b\u5199\u51fa\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u3001\u7b80\u5355\u7684 COBOL \u7f16\u8bd1\u5668\u3002\u5eb7\u5a01\u5728\u6587\u7ae0\u4e2d\u7b2c\u4e00\u6b21\u5f15\u5165\u4e86\u534f\u7a0b\u7684\u6982\u5ff5\u5e76\u5728\u5404\u79cd\u8bed\u8a00\u4e2d\u53d1\u626c\u5149\u5927\uff0c\u800c\u73b0\u5728\u5e38\u89c1\u7684\u7f16\u7a0b\u8bed\u8a00\u90fd\u76f4\u63a5\u6216\u95f4\u63a5\u5730\u5b9e\u73b0\u4e86\u534f\u7a0b\u3002\u5eb7\u5a01\u5728\u4ed6\u7684\u6587\u7ae0\u91cc\u63d0\u51fa\u4e86\u4f4e\u8026\u5408\u7684\u7f16\u7a0b\u6a21\u5f0f\uff0c\u4ed6\u8981\u6c42\uff1a<\/p>\n<ol>\n<li>\u6a21\u5757\u95f4\u7684\u901a\u8fc7\u4f20\u9012\u6d88\u606f\u4ea4\u6d41\u3002<\/li>\n<li>\u8fd9\u4e9b\u6d88\u606f\u6709\u4e00\u4e2a\u56fa\u5b9a\u7684\u3001\u5355\u5411\u7684\u4f20\u9012\u65b9\u5411\u3002<\/li>\n<li>\u7a0b\u5e8f\u53ef\u4ee5\u6309\u5de6\u7aef\u662f\u8f93\u5165\uff0c\u53f3\u7aef\u662f\u8f93\u51fa\u7684\u65b9\u5f0f\u5e03\u7f6e\uff0c\u6240\u6709\u7684\u6d88\u606f\u90fd\u662f\u5411\u53f3\u79fb\u52a8\u7684\u3002<\/li>\n<\/ol>\n<p>\u5728\u4ee5\u4e0a\u7684\u6761\u4ef6\u4e0b\uff0c\u6bcf\u4e00\u4e2a\u6a21\u5757\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u534f\u7a0b\u53bb\u8fd0\u884c\u3002\u534f\u7a0b\u662f\u7279\u6b8a\u7684\u5b50\u4f8b\u7a0b\uff08\u51fd\u6570\u3001\u8fc7\u7a0b\u6216\u65b9\u6cd5\uff09\u3002\u5728 Python \u91cc\u9762\u901a\u8fc7 async def \u5b9a\u4e49\u4e00\u4e2a\u534f\u7a0b\uff0c\u534f\u7a0b\u5c31\u53ef\u4ee5\u901a\u8fc7 yield \uff08\u4e00\u822c\u7ffb\u8bd1\u4e3a\u8ba9\u6b65\uff09\u544a\u8bc9 CPU \u8ba9\u51fa\u81ea\u5df1\u7684\u6267\u884c\u6743\uff0c\u8ba9 CPU \u6267\u884c\u5176\u5b83\u534f\u7a0b\uff0c\u76f4\u5230\u8be5\u534f\u7a0b\u518d\u6b21\u88ab\u663e\u5f0f\u8981\u6c42\u6267\u884c\u3002\u5230\u4e0b\u4e00\u6b21\u6fc0\u6d3b\u6b64\u534f\u7a0b\u65f6\uff0cCPU \u5c06\u4ece\u534f\u7a0b\u4e0a\u6b21 yield \u8fd4\u56de\u7684\u4f4d\u7f6e\u63a5\u7740\u6267\u884c\u3002\u534f\u7a0b\u5728 yield \u8ba9\u51fa\u6267\u884c\u6743\u4ee5\u53ca\u88ab\u518d\u6b21\u7ed9\u4e88\u6267\u884c\u6743\u65f6\u8fd8\u53ef\u4ee5\u8f93\u51fa\u6216\u8f93\u5165\u4e00\u4e2a\u503c\uff0c\u6bcf\u6b21\u5728 yield \u65f6\u8f93\u51fa\u4e00\u4e2a\u503c\u7684\u534f\u7a0b\u4e5f\u88ab\u79f0\u4e3a<strong>\u751f\u6210\u5668<\/strong>\u3002\u534f\u7a0b\u901a\u8fc7 yield \u65b9\u5f0f\u8f6c\u79fb\u6267\u884c\u6743\uff0c\u4e0e\u51fd\u6570\u4e0d\u540c\uff0c\u4e24\u4e2a\u534f\u7a0b\u4e4b\u95f4\u4e0d\u662f\u8c03\u7528\u8005\u548c\u88ab\u8c03\u7528\u8005\u7684\u5173\u7cfb\uff0c\u800c\u662f\u5f7c\u6b64\u5bf9\u79f0\u3001\u5e73\u7b49\u7684\u3002\u534f\u7a0b\u8fd8\u53ef\u4ee5\u901a\u8fc7 await \u5173\u952e\u5b57\u7b49\u5f85\u53e6\u5916\u4e00\u4e2a\u534f\u7a0b\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u534f\u7a0b\u6781\u5927\u5730\u7b80\u5316\u4e86\u5f02\u6b65\u7a0b\u5e8f\uff0c\u5b83\u548c\u5176\u5b83\u534f\u7a0b\u4ea4\u6d41\u7684\u65f6\u5019\u5e76\u4e0d\u662f\u5f3a\u5236\u540c\u6b65\u7684\u3002\u4e3e\u4e2a\u641c\u7d22\u6846\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u8fd9\u4e2a\u641c\u7d22\u51fd\u6570\u4f5c\u4e3a\u4e00\u4e2a\u534f\u7a0b\u8fd0\u884c\uff0c\u628a\u5217\u51fa\u6700\u65b0\u70ed\u8bcd\u4f5c\u4e3a\u53e6\u5916\u4e00\u4e2a\u534f\u7a0b\u8fd0\u884c\uff0c\u8fd9\u6837\u5f53\u6211\u4eec\u7684\u641c\u7d22\u51fd\u6570\u5728\u7b49\u5f85\u7528\u6237\u8f93\u5165\u7684\u65f6\u5019\uff0c\u5217\u51fa\u70ed\u8bcd\u7684\u534f\u7a0b\u5c31\u53ef\u4ee5\u8fd0\u884c\uff0c\u800c\u4e0d\u7528\u4e00\u5b9a\u7b49\u5f85\u7528\u6237\u8f93\u5165\u5b8c\u6210\uff0c\u5728\u7528\u6237\u8f93\u5165\u4e8b\u4ef6\u5b8c\u6210\u540e\uff0c\u641c\u7d22\u51fd\u6570\u5c31\u53ef\u4ee5\u63a5\u53d7\u7528\u6237\u8f93\u5165\u7684\u5173\u952e\u5b57\uff0c\u63a5\u7740\u8fd0\u884c\u3002\u534f\u7a0b\u5171\u7528\u516c\u5171\u7684\u4e8b\u4ef6\u5faa\u73af\u5668\uff08 Eventloop)\uff0c\u4e8b\u4ef6\u5faa\u73af\u5668\u6765\u5bfb\u627e\u53ef\u4ee5\u54cd\u5e94\u7684 I\/O \u4e8b\u4ef6\uff0c\u5e76\u6fc0\u6d3b\u8fd9\u4e9b\u4e8b\u4ef6\u5bf9\u5e94\u7684\u534f\u7a0b\u3002\u6240\u4ee5\u7f16\u5199\u534f\u7a0b\u7a0b\u5e8f\u4e5f\u4f1a\u88ab\u79f0\u4e3a\u7f16\u5199\u4e8b\u4ef6\u9a71\u52a8\u7a0b\u5e8f\u3002<\/p>\n<h1><strong>\u534f\u7a0b\u57fa\u7840\u5bf9\u8c61<\/strong><\/h1>\n<p> <\/p>\n<p>\u672c\u7ae0\u6211\u4eec\u4ecb\u7ecd\u4e00\u4e0b Eventloop\uff0cFuture\uff0cPromise \u548c Generator \u7684\u6982\u5ff5\u3002<\/p>\n<p>Eventloop \uff08\u4e8b\u4ef6\u5faa\u73af\uff09\u662f\u4e00\u4e2a\u5faa\u73af\u67e5\u8be2 I\/O \u4e8b\u4ef6\uff0c\u4f7f\u9047\u5230 I\/O \u963b\u585e\u7684\u4ee3\u7801\u53ef\u4ee5\u5728\u5b83\u9700\u8981\u7684\u65f6\u5019\u8fd0\u884c\u7684\u7a0b\u5e8f\u7ed3\u6784\uff0c\u4e3b\u8981\u7684\u529f\u80fd\u662f<strong>\u7b49\u5f85\u548c\u54cd\u5e94 I\/O \u4e8b\u4ef6<\/strong>\u3002Python \u7684 Eventloop \u63d0\u4f9b\u4e86\u5e38\u7528\u7684\u9488\u5bf9\u7f51\u7edc\u3001\u6587\u4ef6\u548c\u7ba1\u9053\u7684\u4e8b\u4ef6\u6ce8\u518c\u51fd\u6570\uff0c\u4ee5\u53ca\u6267\u884c\u5ef6\u65f6\u4efb\u52a1\u7684 API \u3002Python \u4e8b\u4ef6\u5faa\u73af\u4e3b\u8981\u539f\u7406\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d330d9515.png\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u6bcf\u4e00\u4e2a\u4e8b\u4ef6\u7684\u5bf9\u5e94\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u4e8b\u4ef6\u5faa\u73af\u6bcf\u4e00\u6b21\u5faa\u73af\u91cc\uff0c\u627e\u5230 IO \u5df2\u7ecf\u51c6\u5907\u597d\u7684\u4e8b\u4ef6\uff0c\u5728\u5faa\u73af\u4f53\u91cc\u6267\u884c\u56de\u8c03\u51fd\u6570\u3002\u4e8b\u4ef6\u5faa\u73af\u4e3a\u4e86\u627e\u5230\u5df2\u7ecf\u51c6\u5907\u597d\u7684 I\/O \u4e8b\u4ef6\uff0c\u5728 Linux \u4e0b\u901a\u5e38\u4f7f\u7528\u7cfb\u7edf\u63d0\u4f9b\u7684 epoll API \u3002<\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\uff0cFuture \u548c Promise \u662f\u6307\u7528\u4e8e<strong>\u5728\u5e76\u53d1\u7f16\u7a0b\u8bed\u8a00\u4e2d\u540c\u6b65\u7a0b\u5e8f\u6267\u884c<\/strong>\u7684\u6784\u9020\u3002\u7531\u4e8e\u7f51\u7edc\u8bf7\u6c42\u5c1a\u672a\u7ed3\u675f\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u5bf9\u8c61\u6765\u6682\u65f6\u4ee3\u8868\u51fd\u6570\u7684\u6267\u884c\u7ed3\u679c\uff1b\u5728\u7f51\u7edc\u8bf7\u6c42\u7ed3\u675f\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u5bf9\u8c61\u6765\u83b7\u53d6\u771f\u6b63\u60f3\u8981\u7684\u7ed3\u679c\uff0c\u4e8e\u662f\u5c31\u6709\u4e86\u4e0a\u8ff0\u8fd9\u4e9b\u6784\u9020\u3002Future \u4ece\u5b57\u9762\u4e0a\u8868\u793a\u7684\u662f\u6211\u4eec\u672a\u6765\u5728\u7a0b\u5e8f\u4e2d\u9700\u8981\u83b7\u53d6\u7684\u503c\uff0c\u5176\u672c\u8d28\u662f\u5f02\u6b65\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0c\u901a\u5e38\u4f5c\u4e3a\u4e00\u4e2a\u503c\u7684\u5360\u4f4d\u7b26\u51fa\u73b0\uff1b\u5176\u76ee\u7684\u662f\u8ba9\u5f02\u6b65\u7a0b\u5e8f\u770b\u8d77\u6765\u50cf\u662f\u987a\u5e8f\u6267\u884c\u7684\uff0c\u800c\u4e0d\u662f\u5c06\u5904\u7406\u5f02\u6b65\u51fd\u6570\u8fd4\u56de\u503c\u7684\u4ee3\u7801\u5199\u5728\u53e6\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u91cc\uff0c\u7834\u574f\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002\u5728\u8c03\u7528\u4e00\u4e2a\u5f02\u6b65\u51fd\u6570\u65f6\uff0c\u8be5\u51fd\u6570\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a Future \u5bf9\u8c61\uff0c\u4f46\u771f\u6b63\u7684\u8ba1\u7b97\u8fc7\u7a0b\u4ecd\u5728\u5f02\u6b65\u8fdb\u884c\u4e2d\uff08\u8fd9\u4e2a\u8ba1\u7b97\u7684\u8fc7\u7a0b\u4fbf\u88ab\u79f0\u4e3a Promise\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5728\u5b8c\u7ed3\u65f6\u628a\u7ed3\u679c\u5199\u5165 Future\uff0c\u76f8\u5f53\u4e8e\u505a\u4e86\u4e00\u4e2a\u5728\u201c\u672a\u6765\u201d\u4e00\u5b9a\u4f1a\u7ed9\u51fa\u7ed3\u679c\u7684\u4e00\u4e2a\u201c\u627f\u8bfa\u201d\uff09\uff1b\u6b64\u65f6\u8c03\u7528\u8005\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4e0d\u4f9d\u8d56\u8fd9\u4e2a\u8ba1\u7b97\u7ed3\u679c\u7684\u4efb\u52a1\u800c\u65e0\u9700\u7b49\u5f85\u8ba1\u7b97\u7684\u5b8c\u6210\u3002\u5f53\u8ba1\u7b97\u5b8c\u6210\u65f6\uff0c\u8ba1\u7b97\u51fd\u6570\u5c06\u7ed3\u679c\u8bbe\u7f6e\u7ed9 Future \u5bf9\u8c61\uff0c\u8fd9\u6837\u8c03\u7528\u8005\u5c31\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u503c\u4e86\u3002<\/p>\n<p>Future \u8fd9\u4e2a\u6982\u5ff5\u5728 Python \u4e2d\u6709\u4e00\u4e2a\u5177\u4f53\u7684\u5bf9\u8c61\u6765\u63cf\u8ff0\uff0c\u5b83\u5b9a\u4e49\u4e86\u4ee5\u4e0b\u63a5\u53e3\uff1a<\/p>\n<ul>\n<li>result(),exception() \u83b7\u53d6\u4e00\u4e2a Future \u7684\u503c , \u6216\u8005\u5f02\u5e38;<\/li>\n<li>set_result(value),set_exception(exception) \u8bbe\u7f6e\u4e00\u4e2a Future \u7684\u503c\uff0c\u6216\u8005\u4e00\u4e2a\u5f02\u5e38;<\/li>\n<li>done() \u67e5\u770b\u4e00\u4e2a Future \u662f\u5426\u5df2\u7ecf\u6709\u503c;<\/li>\n<li>cancel(),cancelled() \u53d6\u6d88\u4e00\u4e2a Future\uff0c\u4ee5\u53ca\u67e5\u770b\u4e00\u4e2a Future \u662f\u5426\u88ab\u53d6\u6d88;<\/li>\n<li>add_done_callback(callback,*,context=None),remove_done_callback(callback) \u8bbe\u7f6e\uff0c\u5220\u9664\u4e00\u4e2a Future \u5728\u5b8c\u6210\u65f6\u8fd0\u884c\u7684\u56de\u8c03\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p>\u6bd4\u5982\u4f60\u53bb\u9910\u5385\u5403\u996d\uff0c\u53d1\u73b0\u6ca1\u6709\u5ea7\u4f4d\uff0c\u90a3\u4e48\u6b64\u65f6\u5e97\u5458\u4f1a\u8981\u6c42\u4f60\u626b\u7801\u6392\u961f\uff0c\u626b\u7801\u5b8c\u6210\u540e\u4f60\u7684\u5fae\u4fe1\u91cc\u51fa\u73b0\u4e86\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u544a\u8bc9\u4f60\u5f53\u524d\u6392\u4f4d\u591a\u5c11\u53f7\u3002\u6240\u4ee5\u76f8\u5f53\u4e8e\u6b64\u65f6\u9910\u5385\u5bf9\u4f60\u505a\u51fa\u4e86\u4e00\u4e2a\u201c\u627f\u8bfa(Promise)\u201d\uff0c\u5b83\u627f\u8bfa\u4f60\u5728\u6709\u4f4d\u7f6e\u4e4b\u540e\u4f1a\u901a\u77e5\u4f60\uff1b\u800c\u4f60\u7684\u8fd9\u4e2a\u6392\u961f\u5c0f\u7a0b\u5e8f\u76f8\u5f53\u4e8e\u662f\u4e00\u4e2a Future\uff0c\u4f60\u53ea\u8981\u5e26\u7740\u8fd9\u4e2a\u5c0f\u7a0b\u5e8f\u5c31\u4e0d\u9700\u8981\u5728\u9910\u5385\u95e8\u53e3\u7b49\u4f4d\u800c\u53ef\u4ee5\u51fa\u53bb\u901b\u8857\u4e86\u3002\u8fd9\u4e2a\u5c0f\u7a0b\u5e8f\u901a\u5e38\u4f1a\u6709\u4e09\u4e2a\u529f\u80fd\uff0c\u4e00\u4e2a\u662f\u5728\u6709\u4f4d\u7f6e\u7684\u65f6\u5019\u7ed9\u4f60\u53d1\u9001\u901a\u77e5\uff0c\u76f8\u5f53\u4e8e\u7ed9 Future \u901a\u8fc7 add_done_callback \u8bbe\u7f6e\u7684\u56de\u8c03\u51fd\u6570\uff1b\u53e6\u4e00\u4e2a\u662f\u5141\u8bb8\u4f60\u67e5\u770b\u5f53\u524d\u6392\u4f4d\u662f\u5426\u8f6e\u5230\u4f60\u4e86\uff0c\u76f8\u5f53\u4e8e Future \u4e2d\u7684 done \u51fd\u6570\uff1b\u6700\u540e\u5c31\u662f\u53d6\u6d88\u6392\u961f\uff0c\u76f8\u5f53\u4e8e cancel \u51fd\u6570\u3002\u56e0\u6b64\u5b9e\u9645\u4e0a Future \u548c Promise \u7684\u5e94\u7528\u5728\u751f\u6d3b\u4e2d\u975e\u5e38\u5e38\u89c1\u3002<\/p>\n<p>Generator \uff08\u751f\u6210\u5668\uff09\u662f\u7279\u6b8a\u7684\u4e00\u79cd\u51fd\u6570\uff0c\u53ef\u4ee5\u5728\u6bcf\u4e00\u6b21\u4ea7\u751f\u4e00\u4e2a\u503c\u540e\u9762\u53ef\u4ee5\u628a\u63a7\u5236\u6743\u4ea4\u7ed9\u8c03\u7528\u8005\u3002Generator \u4e5f\u88ab\u79f0\u4e3a <strong>semicoroutine<\/strong> <strong>\uff08<strong><strong>\u534a\u534f\u7a0b<\/strong><\/strong>\uff09<\/strong>\uff0c\u662f\u4e00\u79cd<strong>\u7279\u6b8a\u7684\u3001\u80fd\u529b\u66f4\u5f31\u7684\u534f\u7a0b<\/strong>\u2014\u2014 \u5b83<strong>\u65e0\u6cd5\u5728\u8fd4\u56de\u4e00\u4e2a\u503c\u7684\u65f6\u5019\u6307\u5b9a\u53e6\u5916\u4e00\u4e2a\u534f\u7a0b\u7ee7\u7eed\u6267\u884c<\/strong>\u3002Python \u4e2d\u534f\u7a0b\u7ee7\u627f\u4e86\u751f\u6210\u5668\uff0c\u9664\u4e86\u4f7f\u7528 for \u5faa\u73af\u8fed\u4ee3\u5916\uff0c\u751f\u6210\u5668\u7684\u65b9\u6cd5\u534f\u7a0b\u90fd\u53ef\u4ee5\u8c03\u7528\u3002Generator \u7684\u72b6\u6001\u5b58\u50a8\u548c\u6062\u590d\u7684\u529f\u80fd\u662f\u5b9e\u73b0\u534f\u7a0b\u7684\u57fa\u7840\uff0c\u6709\u4e86\u751f\u6210\u5668\u5c31\u53ef\u4ee5\u5728\u751f\u6210\u5668\u7684\u57fa\u7840\u4e0a\u5b9e\u73b0\u534f\u7a0b\u3002Python \u4e2d\u751f\u6210\u5668\u4f7f\u7528\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d335e0c12.png\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u5f53\u4e00\u4e2a\u51fd\u6570\u5185\u5305\u542b\u4e86 yield \u8bed\u53e5\u65f6\uff0c\u6267\u884c\u5b83\u5c06\u4f1a\u56fa\u5b9a\u8fd4\u56de\u4e00\u4e2a\u751f\u6210\u5668\u5bf9\u8c61\uff0c\u800c\u4e0d\u4f1a\u771f\u6b63\u5730\u6267\u884c\u8fd9\u4e2a\u51fd\u6570\uff0c\u76f4\u5230\u8c03\u7528\u4e86\u8fd9\u4e2a\u5bf9\u8c61\u7684 send \u6216 next \u65b9\u6cd5\u3002<\/p>\n<p>\u901a\u8fc7\u751f\u6210\u5668\u7684 send \u65b9\u6cd5\u6765\u6fc0\u6d3b\u4e00\u4e2a\u751f\u6210\u5668\uff0c\u6bcf\u4e00\u6b21\u8c03\u7528\u6b64\u51fd\u6570\u90fd\u4f1a\u6062\u590d\u751f\u6210\u5668\u7684\u8fd0\u884c\uff0c\u76f4\u5230\u9047\u5230\u4e0b\u4e00\u4e2a yield\uff0c\u5e76\u628a yield \u53f3\u8fb9\u7684\u503c\u8fd4\u56de\u3002\u751f\u6210\u5668\u7ed3\u675f\u7684\u65f6\u5019\u4f1a\u629b\u51fa\u4e00\u4e2a StopIteration \u9519\u8bef\uff0c\u8868\u660e\u5176\u5df2\u7ecf\u7ed3\u675f\u8fd0\u884c\u3002\u751f\u6210\u5668\u5728 yield \u53f3\u8fb9\u8fd4\u56de\u4e00\u4e2a\u503c\uff0c\u5b83\u8fd8\u53ef\u4ee5\u5728 yield \u5de6\u8fb9\u63a5\u6536\u4e00\u4e2a\u503c\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<p><img decoding=\"async\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3af0ac2f.jpg\" \/><\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6c42\u548c\u751f\u6210\u5668\u3002\u5728 g = sum_gen() \u8fd9\u4e00\u53e5\uff0c\u6211\u4eec\u6784\u9020\u4e86\u4e00\u4e2a\u751f\u6210\u5668\uff0c\u6b64\u65f6\u751f\u6210\u5668\u5185\u90e8\u7684\u4ee3\u7801\u8fd8\u6ca1\u6709\u8fd0\u884c\uff0c\u5728 g.send(None) \u8fd9\u4e00\u53e5\uff0c\u751f\u6210\u5668\u5f00\u59cb\u88ab\u6fc0\u6d3b\uff0c\u6b64\u65f6\u751f\u6210\u5668\u4f1a\u8fd0\u884c\u5230\u7b2c\u4e00\u4e2a yield \u7684\u53f3\u8fb9\uff0c\u5373 yield count \u3002\u8fd9\u91cc\u53ef\u4ee5\u5c06 yield count \u770b\u6210\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5b83\u5c06\u4f1a\u5728\u751f\u6210\u5668\u88ab\u6fc0\u6d3b\u65f6\u8fd4\u56de\u4e00\u4e2a\u7531\u5916\u90e8\u7684 send \u65b9\u6cd5\u4f20\u5165\u7684\u503c\uff1b\u4f46\u662f\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u672c\u8eab\u7684\u4f5c\u7528\u662f\u5c06 count \u53d8\u91cf\u4f20\u51fa\u5916\u90e8\u3002\u7b2c\u4e00\u6b21\u6267\u884c\u751f\u6210\u5668\u7684 send \u65b9\u6cd5\u65f6\u4f20\u5165\u7684 None \u5e76\u4e0d\u4f1a\u4f53\u73b0\u5728\u4efb\u4f55\u5730\u65b9\uff0c\u56e0\u4e3a\u5728\u521d\u59cb\u72b6\u6001\u65f6\u7a0b\u5e8f\u5e76\u672a\u6267\u884c\u5230 yield \u90a3\u4e00\u884c\uff0c\u56e0\u6b64\u4f20\u5165\u7684\u8fd9\u4e2a\u503c\u4f1a\u88ab\u76f4\u63a5\u4e22\u5f03\u3002\u7136\u540e\u5728\u4e0b\u9762\u7684\u5faa\u73af\u91cc\uff0c\u6bcf\u4e00\u4e2a\u7528 send \u65b9\u6cd5\u6fc0\u6d3b\u751f\u6210\u5668\u7684\u65f6\u5019\uff0c\u90fd\u4f1a\u9020\u6210\u7c7b\u4f3c yield count \u8bed\u53e5\u8fd4\u56de\u4e86 send \u65b9\u6cd5\u4f20\u5165\u503c\u7684\u6548\u679c\uff0c\u7136\u540e\u7531\u5de6\u8fb9\u7684 total_value \u63a5\u6536\u8be5\u503c\u3002\u751f\u6210\u5668\u8fd8\u6709\u4e00\u4e2a\u6ce8\u610f\u7684\u70b9\u662f\uff0c\u7b2c\u4e00\u6b21\u6fc0\u6d3b\u751f\u6210\u5668\u7684\u65f6\u5019 send \u7684\u53c2\u6570\u5fc5\u987b\u4e3a None\uff0c\u8fd9\u662f\u56e0\u4e3a\u751f\u6210\u5668\u5728\u7b2c\u4e00\u6b21\u88ab\u6fc0\u6d3b\u7684\u65f6\u5019\u4e0d\u662f\u4ece yield \u5de6\u8fb9\u5f00\u59cb\u7684\uff0c\u6ca1\u6709\u8bed\u53e5\u53bb\u63a5\u6536\u4e00\u4e2a\u503c\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u7528 None \u6765\u8868\u793a\u7a7a\u503c\u3002\u4e0a\u9762\u7684\u7a0b\u5e8f\u8fd0\u884c\u7684\u65f6\u5019\u4f1a\u6253\u5370\u5982\u4e0b\u7684\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3b443273.jpg\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u751f\u6210\u5668\u5c06\u4e00\u822c\u7684\u987a\u5e8f\u6267\u884c\u7684\u4ee3\u7801\u53d8\u6210\u4e86\u5206\u6bb5\u6267\u884c\uff0c\u6539\u53d8\u4e86\u6b63\u5e38\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\uff0c\u6211\u4eec\u79f0\u80fd\u5b9e\u73b0\u8fd9\u79cd\u8f6c\u6362\u7684\u673a\u5236\u4e3a\u201c\u63a7\u5236\u6d41\u201d\u3002\u4e0b\u9762\u6211\u4eec\u6765\u770b\u770b\u5728 Python \u4e2d\u63a7\u5236\u6d41\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u3002<\/p>\n<h1><strong>\u63a7\u5236\u6d41\u7684\u5b9e\u73b0<\/strong><\/h1>\n<p> <\/p>\n<p>\u524d\u6587\u5df2\u7ecf\u4ecb\u7ecd\u8fc7\u534f\u7a0b\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u6548\u679c\uff0c\u5728 Python \u4e2d\u8fd9\u4e00\u5207\u662f\u7531\u4e8b\u4ef6\u5faa\u73af\uff08 EventLoop \uff09\u7684\u65b9\u5f0f\u5b9e\u73b0\u7684\u3002<\/p>\n<p>\u4e8b\u4ef6\u5faa\u73af\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u7f16\u7a0b\u6a21\u5f0f\uff0c\u88ab\u5e7f\u6cdb\u8fd0\u7528\u4e8e\u5404\u79cd\u7a0b\u5e8f\u4e2d\u3002\u4f8b\u5982\u51e0\u4e4e\u6240\u6709\u7684\u56fe\u5f62\u5316\u754c\u9762\u90fd\u662f\u4ee5\u4e8b\u4ef6\u5faa\u73af\u7684\u6a21\u5f0f\u6765\u7f16\u5199\u7684\uff0c\u8fd8\u6709\u6bd4\u5982 NodeJS \u76f4\u63a5\u628a\u4e8b\u4ef6\u5faa\u73af\u673a\u5236\u505a\u8fdb\u4e86\u8bed\u8a00\u672c\u8eab\u7684\u7279\u6027\u4e2d\u3002\u901a\u4fd7\u5730\u7406\u89e3\uff0c\u6240\u8c13\u201c\u4e8b\u4ef6\u5faa\u73af\u201d\u5c31\u662f\u4e00\u4e2a\u5faa\u73af\uff0c\u5b83\u4e0d\u65ad\u5730\u63a5\u6536\u4e8b\u4ef6\u5e76\u4e14\u5904\u7406\u4e8b\u4ef6\uff0c\u4e8b\u4ef6\u4e0e\u4e8b\u4ef6\u4e4b\u95f4\u4ece\u4e8b\u4ef6\u5faa\u73af\u7684\u89d2\u5ea6\u770b\u5e76\u6ca1\u6709\u76f8\u5173\u6027\u3002\u5c31\u597d\u6bd4\u6d41\u6c34\u7ebf\u4e0a\u7684\u4e00\u53f0\u673a\u5668\uff0c\u4e00\u5934\u8fdb\u5165\u539f\u6599\uff08\u4e8b\u4ef6\uff09\uff0c\u53e6\u4e00\u5934\u51fa\u6765\u6210\u54c1\uff08\u5904\u7406\u7ed3\u679c\uff09\uff0c\u4ece\u8fd9\u53f0\u673a\u5668\uff08\u673a\u5668\u672c\u8eab\u5bf9\u539f\u6599\u7684\u52a0\u5de5\u8fc7\u7a0b\u5c31\u662f\u4e8b\u4ef6\u89e6\u53d1\u7684\u4e00\u4e2a\u4efb\u52a1\uff09\u7684\u89d2\u5ea6\u770b\uff0c\u539f\u6599 1 \u4e0e\u539f\u6599 2 \u4e4b\u95f4\u6ca1\u6709\u76f4\u63a5\u8054\u7cfb\uff0c\u6210\u54c1 1 \u4e0e\u6210\u54c1 2 \u4e4b\u95f4\u4e5f\u6ca1\u6709\u76f4\u63a5\u8054\u7cfb\u3002\u4f46\u662f\u539f\u6599 1 \u548c\u539f\u6599 2 \u53ef\u80fd\u662f\u7531\u524d\u4e00\u4e2a\u6b65\u9aa4\u4ea7\u751f\u7684\uff0c\u6709\u4e00\u5b9a\u7684\u76f8\u5173\u6027\uff1b\u800c\u6210\u54c1 1 \u548c\u6210\u54c1 2 \u4e5f\u53ef\u80fd\u4f1a\u88ab\u540e\u9762\u7684\u6b65\u9aa4\u5171\u540c\u4f7f\u7528\u3002\u56e0\u6b64\u5e76\u4e0d\u662f\u8bf4\u4e8b\u4ef6\u4e4b\u95f4\u7edd\u5bf9\u72ec\u7acb\uff0c\u53ea\u662f\u4ece\u4e8b\u4ef6\u5faa\u73af\u8fd9\u53f0\u673a\u5668\u7684\u89d2\u5ea6\u770b\u662f\u72ec\u7acb\u7684\u3002<\/p>\n<p>\u5728 Python \u4e2d\uff0c<strong>\u4e8b\u4ef6\u5faa\u73af\u901a\u8fc7 EventLoop \u5bf9\u8c61\u3001Task \u5bf9\u8c61\u548c asyncio \u5e93\u5171\u540c\u5b8c\u6210<\/strong>\u3002\u5f53 EventLoop \u6536\u5230\u4e00\u4e2a\u4e8b\u4ef6\u65f6\uff0c\u4fbf\u4f1a\u521b\u5efa\u4e00\u4e2a Task \u5bf9\u8c61\u6765\u62bd\u8c61\u5316\u8fd9\u4e2a\u4e8b\u4ef6\u6240\u89e6\u53d1\u7684\u5904\u7406\u8fc7\u7a0b\uff08\u5373\u4e0a\u9762\u4f8b\u5b50\u91cc\u673a\u5668\u5bf9\u539f\u6599\u7684\u52a0\u5de5\u4efb\u52a1\uff09\uff0c\u5728 Task \u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\u5982\u679c\u9047\u5230\u4e86 I\/O \u64cd\u4f5c\u3001yield \u8bed\u53e5\u6216\u8005 await \u8bed\u53e5\uff0c\u90a3\u4e48\u4ee3\u8868\u8fd9\u4e2a Task \u5c06\u4f1a\u6682\u65f6\u79bb\u5f00 EventLoop \uff1b\u800c\u4e4b\u540e\u518d\u6b21\u6536\u5230\u6267\u884c\uff08\u4f8b\u5982\u8c03\u7528\u4e86\u751f\u6210\u5668\u7684 send \u65b9\u6cd5\uff0c\u6216\u8005 I\/O \u6570\u636e\u8fd4\u56de\u4e86\uff09\u7684\u4fe1\u53f7\u65f6\uff0cTask \u53c8\u4f1a\u518d\u6b21\u88ab\u4e22\u56de EventLoop \u7ee7\u7eed\u6267\u884c\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f EventLoop \u5728 Task \u6267\u884c\u8fc7\u7a0b\u4e2d\u9047\u5230\u7b49\u5f85\u7684\u72b6\u51b5\u65f6\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u7684\u4efb\u52a1\uff0c\u9ad8\u6548\u5730\u5229\u7528\u4e86 CPU \u5b9d\u8d35\u7684\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u4e3e\u4f8b\u8bf4\u660e\u4e00\u4e0b\u4e00\u4e2a Task \u5b8c\u6574\u7684\u63a7\u5236\u6d41\u662f\u4ec0\u4e48\u6837\u5b50\u7684\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3bb1ca6f.webp\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u7684\u6267\u884c\u6d41\u7a0b\u662f\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3c204ac2.png\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u7a0b\u5e8f\u4ece\u51fd\u6570 print_sum \u5f00\u59cb\u6267\u884c\uff0c\u6267\u884c\u5230 await asyncio.sleep(1.0) \u7684\u65f6\u5019\u9047\u5230\u4e86\u963b\u585e\uff0c\u6b64\u65f6\u534f\u7a0b\u8ba9\u51fa\u6267\u884c\u6743\uff0cEventLoop \u63a5\u7ba1\u7a0b\u5e8f\u3002EventLoop \u7b49\u5f85\u4e00\u79d2\u540e\uff0csleep \u5b8c\u6210\uff0cEventLoop \u6fc0\u6d3b\u4e86 Task\uff0cTask \u4ece sleep \u540e\u9762\u5f00\u59cb\u6267\u884c\uff0ccompute \u8fd4\u56de\u4e86 x+y \u7684\u7ed3\u679c\uff0c \u5176\u503c\u4e3a 3\uff0c\u56e0\u4e3a\u5728 11 \u884c print_sum \u4f7f\u7528\u4e86 await \u7b49\u5f85\u4e86 compute \u7684\u7ed3\u679c\uff0c\u6240\u4ee5 print_sum \u534f\u7a0b\u88ab\u6fc0\u6d3b\uff0c\u6fc0\u6d3b\u540e result \u63a5\u6536\u5e76\u5b58\u50a8\u4e86\u4e00\u4e2a 3\uff0c\u63a5\u7740\u4e0b\u4e00\u884c\u6253\u5370\u4e00\u4e2a\u7ed3\u679c\uff0cprint_sum \u534f\u7a0b\u7ed3\u675f\uff0c\u6b64\u65f6\u6574\u4e2a task \u5b8c\u6210\uff0cTask \u901a\u77e5 EventLoop \u81ea\u5df1\u5df2\u5b8c\u6210\uff0cEventLoop \u5bdf\u89c9\u6240\u6709\u7684 task \u5df2\u5b8c\u6210\uff0cEventLoop \u81ea\u5df1\u9000\u51fa\uff0c \u6574\u4e2a\u7a0b\u5e8f\u5b8c\u6210\u3002<\/p>\n<h1><strong>await \u534f\u7a0b\u539f\u7406<\/strong><\/h1>\n<p> <\/p>\n<p>\u4e00\u4e2a\u534f\u7a0b\u53ef\u4ee5\u5728\u81ea\u5df1\u7684\u8fc7\u7a0b\u91cc await \u53e6\u5916\u4e00\u4e2a\u534f\u7a0b\u7684\u8fd4\u56de\u503c\uff0c\u5b83\u4f1a\u5728 await \u5904\u6302\u8d77\uff0c\u7b49\u5f85\u76f4\u5230 await \u53f3\u8fb9\u7684\u534f\u7a0b\u7ed3\u675f\u3002await \u5728 python \u91cc\u7684\u662f\u901a\u8fc7\u59d4\u6d3e\u751f\u6210\u5668\u5b9e\u73b0\u7684\u3002Python \u91cc\u53ef\u4ee5\u901a\u8fc7 yield from \u5173\u952e\u5b57\u628a\u751f\u6210\u5668 yield \u503c\u7684\u529f\u80fd\u59d4\u6d3e\u7ed9\u53e6\u5916\u4e00\u4e2a\u751f\u6210\u5668\u3002yield from \u7684\u4f7f\u7528\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3c6391ac.png\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u6784\u9020\u7684 gen \u751f\u6210\u5668\u5b9e\u4f8b g (\u7b2c 11 \u884c)\u5c06\u751f\u6210\u503c\u7684\u529f\u80fd\u59d4\u6d3e\u7ed9\u4e86 sub \u751f\u6210\u5668\uff08\u7b2c 7 \u884c\uff09\uff0c\u9047\u5230 yield from \u5173\u952e\u5b57\u7684\u65f6\u5019\uff0c\u6b64\u65f6\u5bf9 gen \u8c03\u7528 send \u65b9\u6cd5\u4f1a\u9a71\u52a8\u59d4\u6d3e\u751f\u6210\u5668\uff08\u6b64\u4f8b\u5b50\u91cc\u662f sub \u751f\u6210\u5668\uff09\u7684\u8fd0\u884c\uff0c\u6bcf\u6b21 send \u8c03\u7528\u5728\u6b64\u65f6\u53ef\u4ee5\u7406\u89e3\u4e3a\u5bf9 sub \u751f\u6210\u5668\u8c03\u7528 send \u65b9\u6cd5\uff0c\u76f4\u5230 sub \u751f\u6210\u5668\u5b8c\u6210\u9000\u51fa\u3002sub \u751f\u6210\u5668\u7ed3\u675f\u540e\uff0c\u7ee7\u7eed\u8c03\u7528 gen \u751f\u6210\u5668\u7684 send \u65b9\u6cd5\u4f1a\u7ee7\u7eed\u6267\u884c gen \u751f\u6210\u5668\u7684\u4ee3\u7801\uff0c\u6700\u7ec8\u4f1a\u5faa\u73af\u6253\u5370\u51fa 1\uff0c2\uff0c1 \u5e8f\u5217\u3002<\/p>\n<p>yield from \u7684\u4f7f\u7528\u4e0d\u9700\u8981\u4efb\u4f55\u7279\u6b8a\u7684\u8c03\u7528\uff0c\u5bf9\u4e8e\u751f\u6210\u5668\u6765\u8bf4\u4ecd\u7136\u662f\u4e0d\u505c\u7684\u8c03\u7528 send \u65b9\u6cd5\u6765\u9a71\u52a8\u751f\u6210\u5668\u7684\u8fd0\u884c\u3002\u4e00\u4e2a\u6709 yield from \u5173\u952e\u5b57\u7684\u751f\u6210\u5668\u5728\u6784\u9020\u7684\u65f6\u5019\u4ee3\u7801\u4fe1\u606f\u4f1a\u5305\u542b\u59d4\u6d3e\u751f\u6210\u5668\u7684\u4ee3\u7801\u5185\u5bb9, \u5728\u4ee3\u7801\u8fd0\u884c\u9047\u5230 yield from \u7684\u65f6\u5019\uff0c\u6fc0\u6d3b\u7684\u751f\u6210\u5668\u65f6\u4f1a\u8fdb\u5165\u5230\u59d4\u6d3e\u751f\u6210\u5668\uff0c\u8fd0\u884c\u59d4\u6d3e\u751f\u6210\u5668\u7684\u4ee3\u7801\uff0c\u59d4\u6d3e\u751f\u6210\u5668\u548c\u751f\u6210\u5668\u4f7f\u7528\u540c\u6837\u7684 send \u4ee3\u7801\u6fc0\u6d3b\u3002yield from \u529f\u80fd\u548c await \u529f\u80fd\u5982\u51fa\u4e00\u8f99\uff0cawait \u5176\u5b9e\u5c31\u662f\u534f\u7a0b\u7248\u7684 yield from \u3002await \u4e00\u4e2a\u534f\u7a0b\u7684\u65f6\u5019\uff0c\u534f\u7a0b\u7684 send \u65b9\u6cd5\u8c03\u7528\u5c31\u8fdb\u5165 await \u53f3\u8fb9\u7684\u7684\u534f\u7a0b\uff0c\u5f00\u59cb\u6267\u884c\u53f3\u8fb9\u534f\u7a0b\u7684 send \u65b9\u6cd5\u3002\u5728 await \u53f3\u8fb9\u534f\u7a0b\u7ed3\u675f\u7684\u65f6\u5019\uff0c\u53f3\u8fb9\u534f\u7a0b\u7684\u8fd4\u56de\u503c\u4f1a\u4f20\u9012\u7ed9 await \u5de6\u8fb9\u7684\u8bed\u53e5\u3002<\/p>\n<h1><strong>Task \u5bf9\u8c61<\/strong><\/h1>\n<p> <\/p>\n<p>Task \u5bf9\u8c61\u662f\u7ba1\u7406\u534f\u7a0b\u6240\u62bd\u8c61\u7684\u5bf9\u8c61\uff0c\u662f\u534f\u7a0b\u8fd0\u884c\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u8f7b\u91cf\u7ea7\u7ebf\u7a0b\uff0c\u5b83\u7684\u6784\u9020\u51fd\u6570\u6bd4\u8f83\u7b80\u5355\uff0c\u63a5\u53d7\u4e00\u4e2a\u534f\u7a0b\u53c2\u6570\uff0c\u590d\u5236\u5f53\u524d\u7684\u4e0a\u4e0b\u6587\u73af\u5883\uff0c\u6784\u9020\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3ca779dd.webp\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>Task \u63a5\u6536\u4e00\u4e2a\u4e3b\u534f\u7a0b\u4e3a\u53c2\u6570\uff0cTask \u4ece\u4e3b\u534f\u7a0b\u5f00\u59cb\u8fd0\u884c\uff0c \u4e3b\u534f\u7a0b\u9000\u51fa\u7684\u65f6\u5019\uff0cTask \u5c31\u5b8c\u6210\u4e86\u3002Task \u751f\u6210\u7684\u65f6\u5019\u548c EventLoop \u7ed1\u5b9a\uff0c\u5728\u7b2c 6 \u884c\uff0c\u4f7f\u7528 loop \u7684 call_soon \u65b9\u6cd5\u6ce8\u518c\u4e86\u4e00\u4e0b\u4e8b\u4ef6\uff0c \u5728 EventLoop \u4e0b\u4e00\u6b21\u5faa\u73af\u7684\u65f6\u5019\uff0cstep \u65b9\u6cd5\u4f1a\u88ab\u7acb\u5373\u8c03\u7528\uff0c\u4ee5\u540e\u6bcf\u4e00\u6b21 Task \u88ab EventLoop \u5524\u9192\u7684\u65f6\u5019\uff0cTask \u7684 step \u65b9\u6cd5\u5c31\u4f1a\u88ab\u8c03\u7528\uff0cstep \u65b9\u6cd5\u7684\u4e3b\u8981\u903b\u8f91\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065d3cded506.jpg\" alt=\"\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio \u6765\u6784\u5efa\u9ad8\u6027\u80fd Python \u7f51\u7edc\u7a0b\u5e8f\" \/><\/p>\n<p>\u7b2c\u4e00\u6b65\u662f\u901a\u544a\u6b64\u65f6\u8fd0\u884c\u7684 Task \u662f\u6211\u81ea\u5df1\uff08\u7b2c 5 \u884c\uff09\uff0c\u7136\u540e\u6fc0\u6d3b\u534f\u7a0b\u7684\u8fd0\u884c\uff0c\u5728\u7b2c 9 \u884c\u91cc\u4f7f\u7528\u4e86 coro.send(None) \u65b9\u6cd5\u6765\u6fc0\u6d3b\u534f\u7a0b\u7684\u8fd0\u884c\u3002\u524d\u9762\u6211\u4eec\u8bb2\u5230\u4e86\u751f\u6210\u5668\uff0c\u751f\u6210\u5668\u662f\u534a\u534f\u7a0b\uff0c\u5728 CPython \u91cc\u9762\uff0c\u534f\u7a0b\u7ee7\u627f\u4e86\u751f\u6210\u5668\u7684\u6240\u6709\u529f\u80fd\uff0c\u6240\u4ee5\u8fd9\u91cc\u8c03\u7528\u7684 send \u65b9\u6cd5\u5c31\u662f\u751f\u6210\u5668\u7684 send \u3002\u534f\u7a0b\u6fc0\u6d3b\u8fd0\u884c\u5b8c\u540e\uff0c\u5982\u679c\u629b\u51fa\u4e86 StopIteration \u5f02\u5e38\uff0c \u8868\u660e\u534f\u7a0b\u4ee5\u8fd0\u884c\u5b8c\u6bd5\uff0c\u5728\u7b2c 15 \u884c\u8bbe\u7f6e\u4e86\u81ea\u5df1\u7684\u8fd4\u56de\u503c\u3002\u5426\u5219\uff0c\u5728 20 \u884c\u53c8\u6ce8\u518c\u4e86\u4e00\u904d\u81ea\u5df1\uff0c\u7b49\u5f85\u4e0b\u4e00\u4e2a\u4e8b\u4ef6\u5faa\u73af\u7ee7\u7eed\u8fd0\u884c\u3002\u6700\u540e\u901a\u544a\u6b64 task \u5728\u6b64\u6b21\u4e8b\u4ef6\u5faa\u73af\u9700\u8981\u8fd0\u884c\u7684\u8fc7\u7a0b\u5df2\u7ed3\u675f\uff0c \u6574\u4e2a\u51fd\u6570\u9000\u51fa\u3002<\/p>\n<h1><strong>\u603b\u7ed3<\/strong><\/h1>\n<p> <\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u4e86\u89e3\u4e86 asyncio \u4f5c\u4e3a\u4e00\u4e2a\u5e93\u505a\u4e86\u4ec0\u4e48\u4ee5\u53ca\u662f\u5982\u4f55\u505a\u7684\uff0c\u603b\u7ed3\u5982\u4e0b\uff1a<\/p>\n<p><strong>1.\u63a7\u5236\u6d41\u7684\u6682\u505c\u4e0e\u6062\u590d<\/strong>\uff0c\u8fd9\u662f Python \u5185\u90e8\u57fa\u4e8e\u751f\u6210\u5668\u76f8\u5173\u7684\u529f\u80fd\u5b9e\u73b0\u7684\uff0c\u901a\u8fc7 send \u65b9\u6cd5\u6fc0\u6d3b\u751f\u6210\u5668\u6765\u6062\u590d\u63a7\u5236\u6d41\uff0c\u901a\u8fc7 yield \u5173\u952e\u5b57\u6765\u6682\u505c\u63a7\u5236\u6d41\uff0c\u8ba9\u51fa\u6267\u884c\u6743\u3002<\/p>\n<p><strong>2.\u534f\u7a0b\u94fe<\/strong>\uff0c\u4e00\u4e2a\u534f\u7a0b\u53ef\u4ee5\u7b49\u5f85\u53e6\u5916\u4e00\u4e2a\u534f\u7a0b\u7684\u8fd0\u884c\u7ed3\u675f\u5e76\u53d6\u5f97\u5b83\u7684\u8fd4\u56de\u503c\u3002<\/p>\n<p><strong>3.\u4e8b\u4ef6\u5faa\u73af<\/strong>\uff0c\u53ef\u4ee5\u8f6e\u8be2 I\/O \u4e8b\u4ef6\uff0c\u5e76\u4e14\u8fd0\u884c\u5b83\u4eec\u6ce8\u518c\u7684\u56de\u8c03\u51fd\u6570\uff0c\u9a71\u4f7f\u6240\u6709\u7684\u534f\u7a0b\u53ef\u4ee5\u5728\u5fc5\u8981\u7684\u65f6\u5019\u8fd0\u884c\u3002<\/p>\n<h1><strong>\u5f15\u7528<\/strong><\/h1>\n<p> <\/p>\n<p>[1].GPU Accelerated Computing with Python<\/p>\n<p>[2].RQData \u4ecb\u7ecd<\/p>\n<p>[3].PEP 492 &#8212; Coroutines with async and await syntax<\/p>\n<p>[4].Conway M E. Design of a separable transition-diagram compiler[J]. Communications of the ACM, 1963, 6(7): 396-408.<\/p>\n<p><strong>\u6bcf\u5929\u8d85\u8fc7 300 \u5bb6\u91d1\u878d\u673a\u6784\u901a\u8fc7 RQData API \u670d\u52a1\u83b7\u53d6\u5404\u79cd\u6807\u7684\u91d1\u878d\u6570\u636e\uff0c\u5728\u534f\u7a0b\u7684\u5e2e\u52a9\u4e0b\uff0c\u6211\u4eec\u901a\u8fc7\u4e00\u79cd\u7b80\u5355\u4e14\u9ad8\u6548\u7684\u65b9\u5f0f\u5b8c\u6210\u4e86\u6b64\u4efb\u52a1\u3002<\/strong> <strong>\u6b22\u8fce\u8054\u7cfb\u7c73\u7b50\u91cf\u5316\u738b\u8001\u5e08\u5fae\u4fe1 RicequantCS \u6c9f\u901a\u5206\u4eab\u66f4\u591a\u91d1\u878d\u6280\u672f\u5e72\u8d27\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u8fdb\u884c RQData \u4ea7\u54c1\u8bd5\u7528\u3002<\/strong><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6280\u672f\u63ed\u79d8 | \u7406\u89e3 asyncio&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419715"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=419715"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419715\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=419715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=419715"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=419715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}