{"id":233499,"date":"2020-12-29T16:13:28","date_gmt":"2020-12-29T08:13:28","guid":{"rendered":"http:\/\/4563.org\/?p=233499"},"modified":"2020-12-29T16:13:28","modified_gmt":"2020-12-29T08:13:28","slug":"twisted-%e6%9c%89%e4%ba%ba%e5%9c%a8%e7%94%a8%e5%90%97-%e6%88%91%e6%98%af%e6%8c%87%e7%9b%b4%e6%8e%a5%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=233499","title":{"rendered":"twisted \u6709\u4eba\u5728\u7528\u5417? \u6211\u662f\u6307\u76f4\u63a5\u4f7f\u7528."},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  twisted \u6709\u4eba\u5728\u7528\u5417? \u6211\u662f\u6307\u76f4\u63a5\u4f7f\u7528.               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chaleaoch <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u57fa\u4e8e twisted \u5f00\u53d1\u9879\u76ee. \u800c\u4e0d\u662f\u5229\u7528\u57fa\u4e8e twisted \u7684\u5176\u4ed6\u4e09\u65b9\u6a21\u5757\u5f00\u53d1.\u8b6c\u5982 channels.<\/p>\n<p>\u4ece\u6211\u5f00\u59cb\u63a5\u89e6 python \u5f00\u59cb, \u5c31\u77e5\u9053 twisted \u4e86. \u4f46\u662f\u6ca1\u89c1\u8fc7\u54ea\u4e2a\u9879\u76ee\u4f7f\u7528. \u800c\u4e14 \u626b\u4e86\u4e00\u773c\u4ee3\u7801\u611f\u89c9\u5f88\u590d\u6742\u7684\u6837\u5b50&#8230;<\/p>\n<p>\u8fd9\u9879\u76ee\u7684\u610f\u4e49\u5728\u54ea\u91cc?<br \/>\u8fd8\u662f\u6211\u89c6\u91ce\u592a\u4e0b\u8f7d\u4e86.      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>16<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4741397\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u670b\u53cb\uff0c\u4f60\u77e5\u9053 Python \u6709 GIL \u561b\uff1f\u56e0\u4e3a GIL \u6240\u4ee5 Python \u7684\u591a\u7ebf\u7a0b\u5e76\u53d1\u57fa\u672c\u4e3a\u5c4e\u3002<\/p>\n<p>\u90a3\u4e2a Python 2.x \u7684\u5e74\u4ee3\uff0cTwisted \u662f\u5199\u975e\u7ebf\u7a0b\u5f02\u6b65\u5e76\u53d1\u4ec5\u6709\u7684\u9009\u62e9\uff08\u4e4b\u4e00\uff09\u3002<\/p>\n<p>\u73b0\u5728\u8fd9\u4e2a\u5e74\u4ee3\u9009\u62e9\u5c31\u591a\u4e86\u3002\u4ece gevent monkey patch\uff0c\u5230 3.5 \u4ee5\u540e\u7684 asyncio \u6807\u51c6\u5e93\u3002\u800c\u4e14\u4ece\u67d0\u79cd\u610f\u4e49\u4e0a\u8bb2\uff0casync io \/ twisted \u8fd9\u79cd\u603b\u4f53\u800c\u8a00\u5199\u670d\u52a1\u5668\u7a0b\u5e8f\u5c31\u662f\u6bd4\u591a\u7ebf\u7a0b\u9ad8\u6548\uff0c\u8fd9\u4e2a\u54ea\u6015\u662f Java\/C#\/Go \u8fd9\u79cd\u591a\u7ebf\u7a0b\u53ef\u7528\u7684\u8bed\u8a00\u4e5f\u662f\u4e00\u6837\u7684\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741398\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : youngce <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             scrapy \u7b97\u662f\u57fa\u4e8e twisted \u7684\u660e\u661f\u9879\u76ee\u4e86\uff08 scrapy \u76ee\u524d\u4e5f\u5728\u652f\u6301 asyncio \uff09\u3002\u8fd9\u4e2a\u9879\u76ee\u786e\u5b9e\u5df2\u7ecf\u8001\u4e86\uff0ctwisted \u4e00\u90e8\u5206\u6838\u5fc3\u4eba\u5458\u4e5f\u90fd\u53bb async io \u8d21\u732e\u4ee3\u7801\u4e86\uff0c\u76ee\u524d\u4f7f\u7528\u4e0a\u6765\u8bf4 asyncio \u662f\u4e3b\u6d41\u4e86\u3002\u518d\u52a0\u4e0a golang \u5199\u7f51\u7edc\u670d\u52a1\u4e5f\u633a\u4e0d\u9519\uff0ctwisted \u786e\u5b9e\u6709\u70b9\u6ca1\u843d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741399\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e4b\u524d\u81ea\u5df1\u5199\u538b\u6d4b\u5de5\u5177\u65f6\u4e86\u89e3\u8fc7\uff0c\u8fd9\u9879\u76ee\u7684\u610f\u4e49\u5c31\u5728\u4e8e\u4ece\u64cd\u4f5c\u7cfb\u7edf\u624b\u91cc\u62a2\u8c03\u5ea6\u6743\uff0c\u51cf\u5c11\u8fd0\u884c\u5355\u5143\u5207\u6362\u6210\u672c\u548c CPU \u5229\u7528\u7387\u3002\u4e0d\u8fc7\u73b0\u5728 Python \u6709 asyncio \u5e93\u4ee5\u53ca async\/await \u8bed\u6cd5\u7cd6\uff0c\u505a\u7c7b\u4f3c\u7684\u4e8b\u60c5\u5df2\u7ecf\u7528\u4e0d\u7740 twisted \u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741400\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chaleaoch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @acmore \u5927\u4f6c\u95ee\u4e00\u4e0b, \u4f60\u77e5\u9053 twisted \u7684\u539f\u7406\u5417?<\/p>\n<p>\u96be\u9053\u662f\u57fa\u4e8e select epoll \u8fd9\u4e9b\u5417?                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741401\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chaleaoch \u8bf4\u4e00\u4e0b\u6211\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u6b22\u8fce\u65a7\u6b63\uff1a<\/p>\n<p>\u9996\u5148 twisted \u548c epoll \u4e0d\u4e00\u6837\uff0c\u5b83\u4eec\u8981\u89e3\u51b3\u7684\u4e0d\u662f\u540c\u4e00\u4e2a\u95ee\u9898\u3002\u524d\u8005\u662f\u60f3\u8981\u5728\u4e0d\u5207\u6362\u7ebf\u7a0b\u7684\u524d\u63d0\u4e0b\u6267\u884c\u591a\u4e2a\u4efb\u52a1\uff0c\u4e3b\u8981\u4e3a\u4e86\u5bf9\u6297 GIL(&lt;strike&gt;Gay In Love&lt;\/strike&gt;)\uff0c\u540e\u8005\u662f\u7528\u66f4\u5feb\u7684\u65f6\u95f4\u6765\u5904\u7406\u66f4\u591a\u7684\u6587\u4ef6\uff08\u7f51\u7edc\u5e94\u7528\u662f\u4e3b\u8981\u65b9\u5411\u4e4b\u4e00\uff09\uff0c\u5373 IO Multiplexing\uff0cepoll \u6a21\u578b\u53ef\u4ee5\u4f5c\u4e3a twisted \u5de5\u4f5c\u7684\u5e95\u5c42\u5e73\u53f0\u4f18\u5316\u624b\u6bb5\uff0c\u4f46\u662f\u4e24\u8005\u65e0\u76f4\u63a5\u5173\u7cfb\uff0ctwisted \u4e3b\u8981\u8fd8\u662f\u5728\u5e94\u7528\u5c42\u505a\u7684\u4f18\u5316\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4 twisted \u4f7f\u7528\u4e86 reactor \u6a21\u578b\uff0c\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u4e00\u5806\u4efb\u52a1\u653e\u5728\u4e00\u4e2a\u961f\u5217\u4e2d\uff0c\u5faa\u73af\u626b\u63cf\uff0c\u8c01\u53d1\u751f\u4e86\u67d0\u4e2a\u4e8b\u4ef6\u5c31\u628a\u5b83\u62ff\u51fa\u6765\u8c03\u7528\u5bf9\u5e94\u7684\u56de\u8c03\u51fd\u6570\uff0c\u8fd9\u70b9\u548c epoll \u505a\u7684\u4e8b\u5f88\u7c7b\u4f3c\uff08\u5728\u4e00\u5806 fd \u91cc\u53ea\u5173\u6ce8\u53d1\u751f\u4e86\u67d0\u4e9b\u4e8b\u4ef6\u7684 fd \uff09\uff0c\u4f46\u5b83\u4eec\u4e0d\u662f\u540c\u4e00\u4e2a\u4e1c\u897f\u3002\u65e2\u7136\u5361\u5355\u7ebf\u7a0b\uff0c\u90a3\u5c31\u8ba9\u5355\u7ebf\u7a0b\u5faa\u73af\u626b\u63cf\u4e00\u5806\u4efb\u52a1\uff0c\u8c01\u4e3e\u624b\u5c31\u6267\u884c\u8c01\uff0c\u53cd\u800c\u5f88\u591a\u60c5\u51b5\u4e0b\u6bd4\u591a\u7ebf\u7a0b\u66f4\u9ad8\u6548\uff08\u514d\u53bb\u4e86\u72b6\u6001\u5207\u6362\u7b49\u4e00\u7cfb\u5217\u5f00\u9500\uff09\uff0c\u574f\u5904\u662f\u5982\u679c\u4e3e\u624b\u7684\u662f\u4e2a\u574f\u5c0f\u5b50\uff0c\u5361\u6b7b\u4e86\u4e3b\u7ebf\u7a0b\uff0c\u90a3\u5176\u4ed6\u4eba\u90fd\u6ca1\u5f97\u73a9\u3002<\/p>\n<p>\u5173\u4e8e epoll \u5e76\u4e0d\u662f\u4e3a\u4e86\u5bf9\u6297\u89e3\u91ca\u5668\u9501\u6216\u8005\u4e4b\u7c7b\u7684\u9650\u5236\u7684\uff0c\u800c\u662f\u4e3a\u4e86\u66f4\u9ad8\u6548\u5730\u5904\u7406\u66f4\u591a\u7684 sockets \uff08\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\uff09\uff0c\u540c\u6837\u53ef\u4ee5\u770b\u4f5c\u662f\u8ba9\u4e00\u5806 fd \u4e3e\u624b\u53d1\u8a00\uff0c\u628a\u4e3e\u624b\u7684\u90a3\u51e0\u4e2a\u635e\u51fa\u6765\u5355\u72ec\u5904\u7406\uff0c\u800c\u4e0d\u7528\u4e00\u4e2a\u4e2a\u5730\u95ee\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741402\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : johnsona <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u53ef\u4ee5\u7f51\u7edc\u7528 go \u5176\u4ed6\u90e8\u5206\u7528\u5176\u4ed6\u8bed\u8a00\uff0c\u6d88\u606f\u961f\u5217\u89e3\u8026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741403\" 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>                                                             @acmore \u5e95\u5c42\u80af\u5b9a\u8fd8\u662f select \u6216\u8005 epoll                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741404\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SlipStupig <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u5bb6\u90fd\u5728\u8bf4\u5386\u53f2\u95ee\u9898\uff0c\u6211\u6765\u8bf4 twisted \u4e00\u4e2a\u4f18\u52bf\uff0c\u5c31\u662f\u51e0\u4e4e\u5b9e\u73b0\u4e86\u76ee\u524d\u5e02\u9762\u4e0a\u7684\u4e3b\u6d41\u534f\u8bae\uff0c\u800c\u4e14\u6027\u80fd\u90fd\u8fd8\u6bd4\u539f\u751f python \u8981\u5f3a\uff0c\u5982\u679c\u8981\u641e\u4e00\u4e9b\u6e38\u620f\u5f00\u53d1\uff0c\u5728\u4eba\u624b\u4e0d\u662f\u5f88\u591a\u7684\u60c5\u51b5\u4e0b twisted \u786e\u5b9e\u6709\u4e00\u5b9a\u7684\u597d\u5904\uff08 twisted \u521d\u8877\u5c31\u662f\u4e3a\u4e86\u5f00\u53d1\u6e38\u620f\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741405\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SlipStupig <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @acmore reactor \u53ea\u662f\u4e00\u79cd I\/O \u6a21\u578b\uff0c\u5e95\u5c42\u4f9d\u7136\u662f epoll \u548c select\uff0ctwisted \u81ea\u8eab\u8fd8\u63d0\u4f9b\u9009\u9879                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741406\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : roundgis <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u76f4\u5728\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741407\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chaleaoch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @SlipStupig \u5927\u4f6c\u591a\u8bb2\u4e24\u53e5.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741408\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chaleaoch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @SlipStupig \u5982\u679c epoll \u5bf9\u8c61\u7684\u56de\u8c03\u9700\u8981 2 \u79d2\u949f. \u90a3\u5c82\u4e0d\u662f\u8fd9\u4e2a\u670d\u52a1\u5668 2 \u79d2\u949f\u4e4b\u5185\u90fd\u6ca1\u54cd\u5e94. \u8fd9\u5e76\u53d1\u91cf\u80fd\u4e0a\u53bb\u5417?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741409\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ruanimal <br \/>@SlipStupig <br \/>\u6ca1\u9519\uff0c\u5e95\u5c42\u662f\uff0c\u800c\u4e14\u76f8\u5f53\u591a\u7684\u4e3b\u6d41\u6846\u67b6\u5e95\u5c42\u90fd\u662f\uff0c\u4f46\u5b83\u4eec\u5e76\u4e0d\u80fd\u8bf4\u662f\u4e00\u56de\u4e8b\uff0c\u6211\u60f3\u8868\u8fbe\u7684\u662f\u8fd9\u4e2a\u533a\u522b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741410\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chaleaoch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @acmore \u5927\u4f6c \u62cd\u8111\u888b\u60f3 \u662f\u4e0d\u662f\u53ef\u4ee5\u8fd9\u6837\u5b9e\u73b0.<br \/>\u8d77\u4e24\u4e2a\u7ebf\u7a0b, \u4e00\u4e2a\u7ebf\u7a0b\u505a epoll , \u6536\u5230\u8fd4\u56de\u503c\u5c31\u5c06 handle \u65b9\u961f\u5217\u91cc.<br \/>\u53e6\u4e00\u4e2a\u7ebf\u7a0b \u5c31\u904d\u5386\u8fd9\u4e2a\u961f\u5217. \u5982\u4f55\u6761\u4ef6\u7684\u5c31\u53bb\u505a\u56de\u8c03\u64cd\u4f5c.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741411\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chaleaoch \u4f60\u53ef\u4ee5\u770b\u4e0b\u6e90\u7801\u5b9e\u73b0\uff08 https:\/\/github.com\/twisted\/twisted\/tree\/41af4fb12e075b8c3aa3cdf6085701195d7f6dae\/src\/twisted\/internet \uff09\uff0c\u4ece\u8fd9\u91cc\u5f00\u59cb\u5f80\u5916\u770b\uff0c\u91cc\u8fb9\u8fd9\u4e00\u5806 *reactor.py \u90fd\u662f\u5bf9\u63a5\u4e86\u4e0d\u540c Reactor \u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u5176\u5b9e\u505a\u7684\u4e8b\u60c5\u5f88\u6734\u7d20\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4741412\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chaleaoch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @acmore \u611f\u8c22\u5927\u4f6c!                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>twisted \u6709\u4eba\u5728\u7528\u5417? \u6211\u662f&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\/233499"}],"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=233499"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/233499\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=233499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=233499"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=233499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}