{"id":713,"date":"2018-10-01T10:34:18","date_gmt":"2018-10-01T02:34:18","guid":{"rendered":"https:\/\/carlos.aboutmy.info\/blog\/?p=713"},"modified":"2018-10-01T10:34:57","modified_gmt":"2018-10-01T02:34:57","slug":"%e5%9f%ba%e6%96%bc-libuv-%e7%9a%84-uvloop-%e4%bb%a4-python-3-5-%e7%9a%84-asyncio-%e6%9b%b4%e5%bf%ab","status":"publish","type":"post","link":"https:\/\/carlos.aboutmy.info\/blog\/?p=713","title":{"rendered":"\u57fa\u65bc libuv \u7684 uvloop \u4ee4 Python 3.5+ \u7684 asyncio \u66f4\u5feb"},"content":{"rendered":"<p>Python 3 \u5df2\u63a8\u51fa\u4e00\u6bb5\u9577\u6642\u9593\uff0c\u6587\u7ae0\u843d\u7b46\u6642\u6700\u65b0\u70ba 3.7\uff0c\u5176\u9593 Python 3 \u90fd\u8b8a\u4e86\u4e0d\u5c11\uff0c3.6 \u8d77\u57fa\u672c\u4e0a\u5df2\u7121\u8a98\u56e0\u7e7c\u7e8c\u7528 2.7\u3002<\/p>\n<p><a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0529\/\">PEP 529 &#8212; Change Windows filesystem encoding to UTF-8<\/a> Windows NT \u6642\u7528\u4e86 UTF-16 \u652f\u63f4 Unicode\uff0c\u4ee4 Windows APIs \u6709\u4e00\u5957 9x \u5e36\u843d ASCII \u7684 *A functions ()\uff0c\u53e6\u4e00\u5957 UTF16LE \u7684 *W Functions\u3002Python 3.6 \u5c31\u540c POSIX APIs \u7747\u9f4a\uff0c\u7528 UTF-8\uff0c\u5373\u540c Linux \u4e0a\u4e00\u6a23\uff0c\u89e3\u6c7a\u597d\u591a cross-platform \u6a94\u6848\u5b58\u53d6\u554f\u984c\u3002<\/p>\n<p><a href=\"https:\/\/www.python.org\/dev\/peps\/pep-3156\/\">PEP 3156 &#8212; Asynchronous IO Support Rebooted: the &#8220;asyncio&#8221; Module<\/a> \/ <a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0492\/\">PEP 492 &#8212; Coroutines with async and await syntax<\/a> \u91cd\u91cf\u7d1a\u5143\u4ef6\uff0casyncio\uff01asyncio \u501f\u7528\u4e86async\/await \u8a9e\u6cd5\uff0casync\/await \u5728 C# \u53ca JavaScript \u4e0a\u90fd\u53ef\u770b\u5230\u5176\u8eab\u5f71\uff0c\u662f non-blocking \u7684\u529f\u81e3\u3002Node.js \u6709\u5169\u6a23\u91ce\u4ee4\u5176\u805e\u540d\u65bc\u4e16\u6709\uff0c\u5c31\u662f V8 engine \u53ca non-blocking runtime\u3002<\/p>\n<p>\u4e0d\u904e asyncio \u4f9d\u7136\u4e0d\u53ca Node.js \u5feb\uff0c\u65bc\u662f\u6709\u4e86 <a href=\"https:\/\/uvloop.readthedocs.io\/\">uvloop<\/a>\u3002uvloop \u662f\u65bc <a href=\"http:\/\/libuv.org\/\">libuv<\/a>\uff0c\u8981\u77e5\u9053 Node.js \u90fd\u662f\u57fa\u65bc libuv \u7684\uff0c\u9019\u53ef\u4ee4 Python 3.5+ \u64fa\u812b\u6bd4 Node.js \u6162\u5f88\u591a\u7684\u554f\u984c\u3002<\/p>\n<p>uvloop \u9084\u4e0d\u662f Python build-in\uff0c\u8981\u4f7f\u7528 uvloop \u9700\u8981\u7528 pip install<\/p>\n<p><code>$ pip install uvloop<\/code><\/p>\n<p>import \u5f8c\u7528\u6cd5\u8ddf asyncio \u4e00\u6a23\u3002<br \/>\n<code><br \/>\nimport asyncio<br \/>\nimport uvloop<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python 3 \u5df2\u63a8\u51fa\u4e00\u6bb5\u9577\u6642\u9593\uff0c\u6587\u7ae0\u843d\u7b46\u6642\u6700\u65b0\u70ba 3.7\uff0c\u5176\u9593 Python 3 \u90fd\u8b8a\u4e86\u4e0d\u5c11\uff0c3.6 \u8d77\u57fa\u672c\u4e0a\u5df2\u7121\u8a98\u56e0\u7e7c\u7e8c\u7528 2.7\u3002 PEP 529 &#8212; Change Windows filesystem encoding to UTF-8 Windows NT \u6642\u7528\u4e86 UTF-16 \u652f\u63f4 Unicode\uff0c\u4ee4 Windows APIs \u6709\u4e00\u5957 9x \u5e36\u843d ASCII \u7684 *A functions ()\uff0c\u53e6\u4e00\u5957 UTF16LE \u7684 *W Functions\u3002Python 3.6 \u5c31\u540c POSIX APIs \u7747\u9f4a\uff0c\u7528 UTF-8\uff0c\u5373\u540c Linux \u4e0a\u4e00\u6a23\uff0c\u89e3\u6c7a\u597d\u591a cross-platform \u6a94\u6848\u5b58\u53d6\u554f\u984c\u3002 PEP 3156 &#8212; Asynchronous IO Support Rebooted:\u2026 <span class=\"read-more\"><a href=\"https:\/\/carlos.aboutmy.info\/blog\/?p=713\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[26,28,29,25,27,30],"_links":{"self":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/713"}],"collection":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=713"}],"version-history":[{"count":2,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/713\/revisions"}],"predecessor-version":[{"id":715,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/713\/revisions\/715"}],"wp:attachment":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}