{"id":137872,"date":"2020-07-21T03:33:31","date_gmt":"2020-07-20T19:33:31","guid":{"rendered":"http:\/\/4563.org\/?p=137872"},"modified":"2020-07-21T03:33:31","modified_gmt":"2020-07-20T19:33:31","slug":"%e6%b1%82%e6%95%99-%e5%8d%8f%e7%a8%8b%e4%b8%8e-io-%e5%a4%9a%e8%b7%af%e5%a4%8d%e7%94%a8%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=137872","title":{"rendered":"[\u6c42\u6559] \u534f\u7a0b\u4e0e IO \u591a\u8def\u590d\u7528\u533a\u522b\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  [\u6c42\u6559] \u534f\u7a0b\u4e0e IO \u591a\u8def\u590d\u7528\u533a\u522b\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kaiser1992 <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u7f51\u4e0a\u641c\u7d22 python asyncio \u5305\u7684\u4ecb\u7ecd\uff0c\u6e05\u4e00\u8272\u90fd\u6d89\u53ca\u5230\u4e86 IO \u591a\u8def\u590d\u7528\uff08 EventLoop \uff09\uff0c\u975e\u963b\u585e\u786e\u5b9e\u80fd\u591f\u63d0\u5347\u6027\u80fd\uff0c\u4f46\u662f\u548c\u534f\u7a0b\u6709\u5565\u5173\u7cfb\u5462~\uff1f<\/p>\n<p>\u6211\u7684\u7591\u60d1\u662f python \u7684\u539f\u751f\u534f\u7a0b\u662f\u57fa\u4e8e\u751f\u6210\u5668\u589e\u5f3a\u6765\u5b9e\u73b0\u7684\uff0c\u600e\u4e48\u4e0e IO \u591a\u8def\u590d\u7528\u5173\u8054\u5230\u4e00\u5757\u5462\uff1f      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>11<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2567574\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u8bae\u4e0d\u8981\u7406\u4f1a\u4e5f\u4e0d\u8981\u4f7f\u7528\u201c\u591a\u8def\u590d\u7528\u201d\u3001\u201c\u975e\u963b\u585e\u201d\u3001\u201c\u534f\u7a0b\u201d\u8fd9\u4e9b\u8bcd\uff0c\u56e0\u4e3a\u4e0d\u540c\u4eba\u4f1a\u6709\u4e0d\u540c\u7684\u7406\u89e3\uff0c\u800c\u4e14\u6ca1\u6cd5\u8fbe\u6210\u4e00\u81f4\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567575\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ruanimal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u534f\u7a0b\u53ea\u662f\u8ba9 eventloop \u5199\u8d77\u6765\u66f4\u65b9\u4fbf\uff0c\u4e0d\u7136\u4f60\u5f97\u5199\u56de\u8c03\u3002<\/p>\n<p>eventloop \u5fc5\u987b\u975e\u963b\u585e\u7684 fd \u52a0\u591a\u8def\u590d\u7528                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567576\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chevalier <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90fd\u5b66\u8fc7\u64cd\u4f5c\u7cfb\u7edf\uff0c\u64cd\u4f5c\u7cfb\u7edf\u7684\u529f\u80fd\u4e4b\u4e00\u5c31\u662f\u63d0\u4f9b\u786c\u4ef6\u7684\u8bbf\u95ee\u63a5\u53e3\uff0c\u4f8b\u5982\uff1a\u7f51\u7edc IO<\/p>\n<p>\u534f\u7a0b\u662f\u201c\u7528\u6237\u6001\u201d\u7684\u6982\u5ff5\uff0cIO \u591a\u8def\u590d\u7528\u662f\u7cfb\u7edf\u8c03\u7528\u7684\u63a5\u53e3\uff0c\u662f\u201c\u7528\u6237\u6001\u201d\u4e0e\u201c\u5185\u6838\u6001\u201d\u4ea4\u4e92\u7684\u65b9\u5f0f\uff1b\u6bd5\u7adf\u534f\u7a0b\u662f\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95ee\u7f51\u5361\u7f13\u51b2\u533a\u7684\uff0c\u9700\u8981\u8c03\u7528\u7cfb\u7edf\u63a5\u53e3\u6765\u83b7\u53d6\u7f51\u7edc IO \u7684\u6570\u636e\u3002<\/p>\n<p>\u6240\u4ee5\u7f51\u7edc\u7a0b\u5e8f\uff0c\u534f\u7a0b\u4e00\u822c\u9700\u8981\u642d\u914d IO \u591a\u8def\u590d\u7528\u624d\u80fd\u53d1\u6325\u6700\u5927\u5a01\u529b\uff0c\u534f\u7a0b\u63d0\u5347\u5e76\u53d1\u5904\u7406\u7684\u80fd\u529b\uff0c\u7f51\u7edc IO \u80fd\u529b\u5c31\u8981\u9760 IO \u591a\u8def\u590d\u7528\u3002<\/p>\n<p>\u8bf4\u5f97\u6bd4\u8f83\u7b80\u5355\uff0c\u7ec6\u8bf4\u4e86\u80fd\u5199\u597d\u51e0\u7bc7\u6587\u7ae0\u4e86\u3002\u5efa\u8bae\u770b\u770b tornado\/asyncio \u7684\u6e90\u7801\uff0c\u7f51\u7edc\u901a\u4fe1\u6a21\u5757\uff0c\u6216\u8005\u81ea\u5df1\u7528 C \u5199\u4e00\u5199 epoll \u7cfb\u7edf\u8c03\u7528\uff0c\u5c31\u5bb9\u6613\u7406\u89e3\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567577\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coldmonkeybit <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u501f\u8bf7\u6559\uff0c\u6ca1\u7528\u8fc7 Python\uff0c\u8bf7\u95ee python \u4e2d\u7684\u534f\u7a0b\u8ddf go \u7684\u534f\u7a0b\u7c7b\u4f3c\u4e48\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567578\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : kaiser1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chevalier \u6240\u4ee5\u8bf4\uff0c\u5982\u679c\u6211\u7684\u7a0b\u5e8f\u4e00\u70b9\u6ca1\u6709 IO\uff0c\u534f\u7a0b\u6267\u884c\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u4f1a\u7528\u5230\u591a\u8def\u590d\u7528\u7684\u673a\u5236\u4e86\u5427~\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567579\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : palfortime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u534f\u7a0b\u548c io \u591a\u8def\u590d\u7528\u662f\u4e24\u4e2a\u7ef4\u5ea6\u7684\u4e1c\u897f\uff0c\u534f\u7a0b\u53ea\u8981\u6709 io \u5c31\u53ef\u4ee5\u6d3e\u4e0a\u7528\u9014\uff0c\u7ebf\u7a0b\u4e5f\u53ef\u4ee5\u642d\u914d io \u591a\u8def\u590d\u7528\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567580\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : guochao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &gt; \u5982\u679c\u6211\u7684\u7a0b\u5e8f\u4e00\u70b9\u6ca1\u6709 IO\uff0c\u534f\u7a0b\u6267\u884c\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u4f1a\u7528\u5230\u591a\u8def\u590d\u7528\u7684\u673a\u5236\u4e86\u5427~\uff1f<\/p>\n<p>\u5bf9\uff0c\u5982\u679c\u4e00\u4e2a\u7a0b\u5e8f\u6ca1\u6709 IO \u548c\u5176\u4ed6\u6682\u505c\u7ebf\u7a0b\u7684\u624b\u6bb5\uff0c\u4e5f\u5c31\u662f\u8bf4\u662f\u300a\u8ba1\u7b97\u5bc6\u96c6\u578b\u300b\u7684\u7a0b\u5e8f\uff0c\u90a3\u4e48\u5c31\u548c\u591a\u8def\u590d\u7528\u65e0\u5173\uff0c\u6bd5\u7adf\u8fd9\u662f\u4e2a IO \u6982\u5ff5\u3002<\/p>\n<p>\u534f\u7a0b\u7684\u672c\u8d28\u662f\u5229\u7528\u591a\u8def\u590d\u7528\u548c\u4fe1\u53f7\u5c3d\u53ef\u80fd\u591a\u7684\u300a\u5728\u540c\u4e00\u4e2a\u7ebf\u7a0b\u4e0a\u8dd1\u66f4\u591a\u7684\u4efb\u52a1\u300b\uff0cIO \u548c\u4f11\u7720\u7684\u65f6\u5019\u534f\u7a0b\u5c31\u4f1a\u6682\u505c\uff0c\u9047\u5230\u4fe1\u53f7\u5c31\u4f1a\u5524\u9192\u3002\u65e0\u975e\u5c31\u662f\u628a\u4ee5\u524d\u7684\u56de\u8c03\u6362\u4e86\u4e00\u79cd\u5f62\u5f0f\uff0c\u8ba9\u56de\u8c03\u53d8\u6210\u987a\u5e8f\u7684\u8fc7\u7a0b\uff0c\u66f4\u9002\u5408\u4eba\u7c7b\u7406\u89e3\u3002<\/p>\n<p>\u300a IO \u5bc6\u96c6\u578b\u300b\u7684\u7a0b\u5e8f\u5229\u7528\u534f\u7a0b\u53ef\u4ee5\u83b7\u53d6\u300a\u66f4\u9ad8\u7684\u5e76\u53d1\u5ea6\uff08\u540c\u4e00\u4e2a\u7ebf\u7a0b\u4e0a\u53ef\u4ee5\u8dd1\u66f4\u591a\u7684 IO \u4efb\u52a1\uff09\u300b\uff0c\u4f46\u662f\u4e5f\u4f1a\u5e26\u6765\u300a\u66f4\u9ad8\u7684\u5ef6\u8fdf\uff08\u5524\u9192\u548c\u8c03\u5ea6\u7684\u5f00\u9500\uff09\u300b\u3002\u8ba1\u7b97\u5bc6\u96c6\u578b\u7684\u7a0b\u5e8f\u51e0\u4e4e\u4e0d\u4f1a\u6709\u4efb\u4f55\u63d0\u5347\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567581\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dongcidaci <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6597\u80c6\u8bf4\u4e00\u4e0b\uff0c\u534f\u7a0b\u5c31\u662f\u7528\u6237\u6001\u7684\u7ebf\u7a0b\uff0c\u4e0a\u4e0b\u6587\u5207\u6362\u5f00\u9500\u5c0f\u3002\u591a\u8def\u590d\u7528\u662f\u4e00\u79cd IO \u65b9\u5f0f\u3002\u8c8c\u4f3c\u6ca1\u4ec0\u4e48\u5173\u7cfb\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567582\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u63a8\u8350\u770b\u4e00\u4e0b\u8fd9\u7bc7\u6587\u7ae0 https:\/\/blog.panicsoftware.com\/coroutines-introduction\/<\/p>\n<p>\u6211\u4e2a\u4eba\u7684\u7406\u89e3\uff0c\u65e0\u6808\u534f\u7a0b\u662f\u4e00\u79cd\u53ef\u4ee5\u4e2d\u9014\u8fd4\u56de\uff0c\u540e\u9762\u518d\u4ece\u4e4b\u524d\u8fd4\u56de\u7684\u5730\u65b9\u6062\u590d\u6267\u884c\u7684\u51fd\u6570\u3002\u5229\u7528\u8fd9\u79cd\u7279\u6027\u53ef\u4ee5\u5b9e\u73b0\u8bb8\u591a\u529f\u80fd\uff0c\u6bd4\u5982\u751f\u6210\u5668\uff0c\u6c42\u51fa\u4e00\u4e2a\u503c\u4e4b\u540e\u8fd4\u56de\uff0c\u9700\u8981\u4e0b\u4e00\u4e2a\u503c\u7684\u65f6\u5019\u518d\u6062\u590d\u6267\u884c\u3002\u6216\u8005\u7528\u6765\u7f16\u5199\u5f02\u6b65 IO \u4ee3\u7801\uff0c\u5728\u5f00\u59cb IO \u64cd\u4f5c\u540e\u8fd4\u56de\uff0cIO \u64cd\u4f5c\u5b8c\u6210\u4e4b\u540e\u6062\u590d\u6267\u884c\u3002<br \/>\u800c\u5f02\u6b65 IO \u53c8\u6709\u591a\u79cd\u5b9e\u73b0\u65b9\u5f0f\u3002\u53ef\u4ee5\u7528\u6700\u7b80\u5355\u7684\u591a\u7ebf\u7a0b\u6765\u5b9e\u73b0\uff0c\u534f\u7a0b\u542f\u52a8\u4e00\u4e2a\u65b0\u7ebf\u7a0b\u6765\u8fdb\u884c\u963b\u585e IO \u64cd\u4f5c\uff0c\u540c\u65f6\u8fd4\u56de\uff0c\u65b0\u7ebf\u7a0b\u4e2d\u7684 IO \u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u5728\u65b0\u7ebf\u7a0b\u4e2d\u6062\u590d\u6267\u884c\u534f\u7a0b\u3002<br \/>\u4e5f\u53ef\u4ee5\u7528\u5355\u7ebf\u7a0b\u6765\u5b9e\u73b0\uff0c\u4f46\u662f\u8981\u914d\u5408 IO \u591a\u8def\u590d\u7528\u6765\u5b9e\u73b0\uff0cIO \u591a\u8def\u590d\u7528\u7b80\u5355\u8bf4\u662f\u540c\u65f6\u76d1\u89c6\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5426\u5c31\u7eea\uff0c\u534f\u7a0b\u5728\u5f53\u524d\u7ebf\u7a0b\u8fdb\u884c\u975e\u963b\u585e\u7684 IO \u64cd\u4f5c\u4e4b\u540e\u8fd4\u56de\uff0c\u7136\u540e\u5f53\u524d\u7ebf\u7a0b\u4f1a\u68c0\u6d4b\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5426\u5c31\u7eea\uff0c\u5c31\u7eea\u540e\u6062\u590d\u6267\u884c\u534f\u7a0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567583\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u603b\u7ed3\u8d77\u6765\u662f\uff0c\u534f\u7a0b\u8ddf IO \u591a\u8def\u590d\u7528\u5173\u7cfb\u4e0d\u5927\uff0c\u56e0\u4e3a\u5b8c\u5168\u53ef\u4ee5\u7528\u534f\u7a0b\u5199\u4e00\u4e2a\u4e0d\u6d89\u53ca IO \u64cd\u4f5c\u7684\u4ee3\u7801\uff0c\u5373\u4f7f\u6d89\u53ca\u5230\u4e86 IO \u64cd\u4f5c\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u7684\u6a21\u578b\u3002<br \/>Python \u7684 asyncio \u9009\u62e9\u4e86\u5355\u7ebf\u7a0b+IO \u591a\u8def\u590d\u7528\u7684\u6a21\u578b\uff0c\u6240\u4ee5\u76f8\u5173\u8d44\u6599\u90fd\u4f1a\u6d89\u53ca\uff0c\u4f46\u662f asyncio \u5e76\u4e0d\u7b49\u540c\u4e8e\u534f\u7a0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2567584\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : irosyking <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1 \u3001Async IO Framework = eventloop + non-blocking sockets + coroutines <br \/> Async IO Framework = eventloop + non-blocking sockets + callbacks<\/p>\n<p>2 \u3001Coroutine = Future + Task + Generator<br \/> Lazy computation = Generator                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>[\u6c42\u6559] \u534f\u7a0b\u4e0e IO \u591a\u8def\u590d\u7528\u533a&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\/137872"}],"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=137872"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/137872\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=137872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=137872"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=137872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}