{"id":318507,"date":"2021-02-05T00:14:04","date_gmt":"2021-02-04T16:14:04","guid":{"rendered":"http:\/\/4563.org\/?p=318507"},"modified":"2021-02-05T00:14:04","modified_gmt":"2021-02-04T16:14:04","slug":"%e9%97%ae%e4%b8%80%e4%b8%aa%e5%85%b3%e4%ba%8e-asyncio-%e7%9a%84%e9%97%ae%e9%a2%98%ef%bc%8c%e5%bd%93%e5%a4%9a%e4%b8%aa-task-%e8%bf%90%e8%a1%8c%ef%bc%8c%e5%85%b6%e4%b8%ad%e4%b8%80%e4%b8%aa%e6%ad%a3","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=318507","title":{"rendered":"\u95ee\u4e00\u4e2a\u5173\u4e8e asyncio \u7684\u95ee\u9898\uff0c\u5f53\u591a\u4e2a task \u8fd0\u884c\uff0c\u5176\u4e2d\u4e00\u4e2a\u6b63\u786e\u8fd4\u56de\u540e\uff0c\u600e\u4e48\u53d6\u6d88\u5176\u4ed6\u534f\u7a0b\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u95ee\u4e00\u4e2a\u5173\u4e8e asyncio \u7684\u95ee\u9898\uff0c\u5f53\u591a\u4e2a task \u8fd0\u884c\uff0c\u5176\u4e2d\u4e00\u4e2a\u6b63\u786e\u8fd4\u56de\u540e\uff0c\u600e\u4e48\u53d6\u6d88\u5176\u4ed6\u534f\u7a0b\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dongcheng <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50 <code> import asyncio import time<\/code><\/p>\n<p><code> <\/p>\n<h1>\u7279\u6b8a\u51fd\u6570<\/h1>\n<p> <code class=\"language-python hljs\"> async def get_request(url): print('\u6b63\u5728\u4e0b\u8f7d',url) # time.sleep(2) \u4e0d\u652f\u6301\u5f02\u6b65\u7684\u6a21\u5757 \u4f1a\u4e2d\u65ad\u6574\u4e2a\u7684\u5f02\u6b65\u6548\u679c await asyncio.sleep(2) print('\u4e0b\u8f7d\u5b8c\u6210',url) return 'page_text' <\/p>\n<p>def parse(task): print(task.result())<\/p>\n<p>start = time.time() urls = ['www.xxx1.com','www.xxx2.com','www.xxx3.com']<\/p>\n<p>tasks = [] #\u5b58\u653e\u591a\u4efb\u52a1 for url in urls: # \u8c03\u7528\u7279\u6b8a\u51fd\u6570 func = get_request(url)<\/p>\n<pre><code># \u521b\u5efa\u4efb\u52a1\u5bf9\u8c61 task = asyncio.ensure_future(func)  # \u7ed9\u4efb\u52a1\u5bf9\u8c61\u7ed1\u5b9a\u56de\u8c03\u51fd\u6570 task.add_done_callback(parse) tasks.append(task) <\/code><\/pre>\n<h1>\u521b\u5efa\u4e8b\u4ef6\u5faa\u73af\u5bf9\u8c61<\/h1>\n<p> <\/p>\n<p>loop = asyncio.get_event_loop()<\/p>\n<h1>\u6267\u884c\u4efb\u52a1<\/h1>\n<p> <\/code><\/p>\n<p><code>loop.run_until_complete(asyncio.wait(tasks)) print('\u603b\u8017\u65f6:',time.time()-start) #2.0015313625335693 <\/code><\/p>\n<p>\u53ef\u4ee5\u5728 get_request \u5224\u65ad\u4efb\u52a1\u662f\u5426\u6210\u529f\uff0c\u4f46\u662f\u5982\u4f55\u5224\u65ad\u6210\u529f\u4e4b\u540e\u53d6\u6d88\u5176\u4ed6\u4efb\u52a1\u5462\uff1f<\/p>\n<p>\u8c22\u8c22<\/p>\n<p> <\/code>  <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>23<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5058668\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chanchancl <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c06 func \u5305\u88c5\u6210\u4e00\u4e2a function<\/p>\n<p>\u5728\u7ed3\u5c3e\u7684\u5730\u65b9\uff0c\u5c06 tasks \u4e2d\uff0c\u9664\u4e86\u81ea\u5df1\u7684 task \u90fd cancle \u6389                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058669\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pursuer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u60f3\u8981\u8ba9\u534f\u7a0b\u63d0\u524d\u7ed3\u675f\u7b49\u5f85\uff0c\u53ef\u4ee5\u4f7f\u7528 asyncio.wait(&#8230;,return_when=&#8217;FIRST_COMPLETED&#8217;)\u6216\u8005\u66f4\u7075\u6d3b\u7684\u65b9\u6848 asyncio.Future\uff0c\u7136\u540e\u5904\u7406\u4e0b\u8d44\u6e90\u91ca\u653e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058670\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dongcheng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @chanchancl \u8fd9\u4e2a func \u80fd\u83b7\u53d6\u5230 task \u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058671\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u662f\u4e0d\u662f\u60f3\u9519\u4e86\uff0c\u5bf9\u4e8e\u534f\u7a0b\u6765\u8bf4\uff0c\u5982\u679c\u8bbe\u8ba1\u5230 io\uff0c\u90a3\u4e48\u5c31\u7b97\u80fd\u53d6\u6d88\u534f\u7a0b\u5176\u5b9e\u5e76\u4e0d\u80fd\u53d6\u6d88 io \u64cd\u4f5c<\/p>\n<p>\u6bd4\u5982 http \u8bf7\u6c42\uff0c\u5c31\u7b97\u4f60\u8981\u53d6\u6d88\u534f\u7a0b\u5176\u5b9e\u5e76\u4e0d\u80fd\u53d6\u6d88\u5df2\u7ecf\u53d1\u9001\u51fa\u53bb\u7684 http \u8bf7\u6c42\uff0c\u53d6\u6d88\u534f\u7a0b\u5b8c\u5168\u6ca1\u6709\u610f\u4e49\uff0c\u5982\u679c\u4f60\u80fd\u53d6\u6d88 io\uff0c\u6bd4\u5982\u5173\u95ed http \u8fde\u63a5\u6765\u53d6\u6d88 http \u8bf7\u6c42\uff0c\u90a3\u4e48\u4f60\u5e94\u8be5\u901a\u8fc7\u5173\u95ed http \u8bf7\u6c42\u7684\u65b9\u5f0f\u6765\u89e6\u53d1\u534f\u7a0b\u8fd4\u56de\uff0c\u5373\u5148\u53d6\u6d88 io \u64cd\u4f5c\u518d\u7531 io \u5b8c\u6210\u6765\u89e6\u53d1\u534f\u7a0b\u8fd4\u56de\uff0c\u800c\u4e0d\u80fd\u5012\u8fc7\u6765<\/p>\n<p>\u5bf9\u4e8e\u975e io \u8bf7\u6c42\uff0c\u518d\u6574\u4e2a\u534f\u7a0b\u5b8c\u6210\u524d\u4f1a\u72ec\u5360\u7ebf\u7a0b\uff0c\u5e76\u4e0d\u4f1a\u8c03\u5ea6\u5230\u5176\u4ed6\u534f\u7a0b\uff0c\u6240\u4ee5\u4f60\u81ea\u7136\u4e5f\u4e0d\u80fd\u7528\u5176\u4ed6\u534f\u7a0b\u6765\u53d6\u6d88\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u534f\u7a0b\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058672\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : keepeye <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u662f\u6709 tasks \u5417\uff1f\u904d\u5386\u4e00\u4e0b\u90fd cancel \u6389                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058673\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fiveelementgid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u89c1 Task \u548c continuation \u8fd8\u6fc0\u52a8\u4e86\u4e00\u4e0b\u4ee5\u4e3a\u6709. NET \u73a9\u5bb6\u4e00\u8d77\u7814\u7a76 TAP \u4e86\uff0c\u4e00\u770b\u662f Python\uff0c\u544a\u8f9e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058674\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bf9\u4e8e\u975e io \u8bf7\u6c42\u534f\u7a0b\u518d\u8865\u5145\u4e00\u70b9\uff0c\u4f3c\u4e4e\u534f\u7a0b\u518d\u521b\u5efa\u7684\u65f6\u5019\u5c31\u4f1a\u8fdb\u884c\u9996\u6b21\u8fd0\u884c\uff0c\u6ca1 io \u64cd\u4f5c\uff0c\u6240\u4ee5\u9996\u6b21\u8fd0\u884c\u5fc5\u7136\u72ec\u5360\u7ebf\u7a0b\u4e00\u76f4\u5230\u8fd0\u884c\u5b8c\u6210\uff0c\u6240\u4ee5\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5b8c\u5168\u505a\u4e0d\u4e86\u4e2d\u9014\u53d6\u6d88\u7684\u64cd\u4f5c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058675\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dongcheng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 \u5e94\u8be5\u53ef\u4ee5\u53d6\u6d88 task \u5427\u3002\u53ea\u662f\u6709\u5c40\u9650\u3002<\/p>\n<p>@keepeye asyncio.Task.all_tasks()\u53ef\u4ee5\u83b7\u53d6 all task \u3002\u4f46\u662f\u73b0\u5728\u6709\u4e2a\u9700\u6c42\u662f\u5d4c\u5957\u7684 task\uff0c\u53ef\u4ee5\u53d6\u6d88\u6240\u6709 task\uff0c\u4e0d\u80fd\u53d6\u6d88\u7b2c 2 \u5c42\u7684 task \uff08\u4fdd\u7559\u7b2c\u4e00\u5c42\uff09                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058676\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dongcheng #8 \u4f46\u662f\u6ca1\u610f\u4e49\uff0c\u4e0d\u7b26\u5408\u534f\u7a0b\u539f\u7406\u5b9e\u73b0\uff0c\u4ece\u7a0b\u5e8f\u7684\u53ef\u9760\u6027\u4e25\u8c28\u6027\u6765\u8bf4\u4e5f\u4e0d\u5e94\u8be5\u51fa\u73b0\u8fd9\u79cd\u8bbe\u8ba1\uff0c\u4e0d\u5173\u95ed io \u800c\u53d6\u6d88\u4e0a\u5c42\u534f\u7a0b\u662f\u5f88\u4e0d\u79d1\u5b66\u7684\uff0c\u5f88\u5bb9\u6613\u5bfc\u81f4 io \u3001\u8fde\u63a5\u6cc4\u9732\u5565\u7684\uff0c\u800c\u4e14\u8fd8\u4e0d\u5bb9\u6613\u6392\u67e5\u662f\u5565\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058677\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaoHuang3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 \u9644\u8bae\uff5e\uff0c\u6211\u89c9\u5f97\u4e3b\u8fd9\u79cd\u9700\u6c42\u6839\u672c\u4e0d\u9002\u5408\u7528 asyncio \u6765\u505a- &#8211;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058678\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : crclz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @fiveelementgid .NET \u7684\u8bbe\u8ba1\u5c31\u5f88\u6e05\u6670\uff0cTAP \u3001cancellation token<\/p>\n<p>\u5982\u679c\u662f.NET \u7684\u8bdd\uff0c\u5e94\u8be5\u628a\u4e00\u4e2a CancellationTokenSource \uff08 cts \uff09\u7684 CancellationToken \u4f20\u7ed9\u6240\u6709\u5f02\u6b65\u65b9\u6cd5\uff0c\u5f02\u6b65\u65b9\u6cd5\u4f1a\u8fd4\u56de task\uff0c\u518d\u7b49 Task.WhenAny \u8fd4\u56de\u540e\uff0c\u518d\u53d6\u6d88 cts \u3002<\/p>\n<p>\u7531\u4e8e CancellationToken \u662f\u5c42\u5c42\u6df1\u5165\u7684\uff08 HTTP \u3001TCP \uff09\uff0c\u6240\u4ee5\u5e95\u5c42\u8d1f\u8d23 TCP \u7684\u4ee3\u7801\u4e5f\u4f1a\u53d6\u6d88\u6b63\u5728\u8fdb\u884c\u7684\u64cd\u4f5c\uff0c\u7136\u540e\u4f1a\u6254\u51fa\u4e00\u4e2a\u53d6\u6d88\u5f02\u5e38\uff0c\u6700\u540e\u6355\u83b7\u8fd9\u4e2a\u5f02\u5e38\u5c31\u884c\u4e86\uff08\u5728\u5f02\u6b65\u65b9\u6cd5\u4e2d\uff09\u3002<\/p>\n<p>\u6211\u60f3 python \u7684\u95ee\u9898\u5c31\u662f\uff0c\u5e95\u5c42\u7684 api \u90fd\u6ca1\u6709\u63d0\u4f9b cancellation token \u7684\u53c2\u6570\uff0c\u5bfc\u81f4\u65e0\u6cd5\u8ba9\u53d6\u6d88\u64cd\u4f5c\u5c42\u5c42\u4f20\u64ad\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058679\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5199\u8fc7\u76f8\u5173\u4ee3\u7801\uff0c\u5728\u6211\u7684\u9879\u76ee\u91cc\u4f7f\u7528\u8fc7\u5f88\u4e45\uff0c\u4e00\u5207\u826f\u597d\u3002<\/p>\n<p>https:\/\/gist.github.com\/abersheeran\/bd2372bb35fec859d7fca453ca5f7826 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058680\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u521a\u770b\u5230\u4e3b\u5728 #8 \u8bf4\u6709\u5d4c\u5957 Task \u3002\u5f88\u9057\u61be\uff0casyncio \u4e0d\u652f\u6301\u5d4c\u5957\u53d6\u6d88\u3002\u53ef\u4ee5\u8bd5\u8bd5 trio\uff0c\u5ba3\u4f20\u4e0a\u8bf4\u662f\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002\u6211\u4e5f\u6ca1\u8bd5\u8fc7\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058681\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : optional <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ece\u8bbe\u8ba1\u4e0a\u6765\u8bf4\uff0c\u8fd9\u662f\u4e0d\u53ef\u53d6\u6d88\u7684\uff0c\u5982\u679c\u6709 transaction \u5bf9\u8c61\u4e4b\u7c7b\uff0c\u53ef\u4ee5\u6807\u8bb0\u4e00\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058682\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fiveelementgid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @crclz Sure\uff0c\u6211\u6628\u665a\u521a\u770b\u5b8c\u5370\u8c61\u6df1\u523b\uff0c\u7279\u5730\u8fd8\u53bb\u6252\u4e86\u4e00\u4e0b\u6e90\u7801\u3002\u6700\u5e95\u4e0b\u5c31\u662f new \u4e00\u4e2a\u65b0\u7684 Token \u548c\u4e0a\u5c42\u4f20\u4e0b\u6765\u7684 Token \u7136\u540e Link\uff0c\u6574\u5c42\u6574\u5c42\u5730\u63a7\u5236                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058683\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dongcheng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @abersheeran \u611f\u8c22\u5206\u4eab\u4ee3\u7801\u3002\u7814\u7a76\u4e86\u4e0b asyncio.as_completed(tasks)\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u4f3c\u7684\u529f\u80fd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058684\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhuangzhuang1988 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @crclz \u5fae\u8f6f\u8fd8\u662f\u6700\u725b\u7684<br \/>cancal \u8fdb\u5ea6\u62a5\u544a\u662f api \u4e2d\u8bbe\u8ba1\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058685\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuboying <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @abersheeran #12 \u4e2a\u4eba\u611f\u89c9\u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\u7528\u7c7b\u6765\u5b9e\u73b0\u53ef\u8bfb\u6027\u53ef\u80fd\u4f1a\u66f4\u597d\u4e00\u70b9\u3002loop = loop or asyncio.get_running_loop()\u5b66\u5230\u4e86\u3002\u4e4b\u524d\u5199\u7684\u65f6\u5019\u8fd8\u6ca1\u8fd9\u4e2a\u51fd\u6570\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058686\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u521a\u597d\u6709\u7c7b\u4f3c\u9700\u6c42<br \/>\u6ca1\u627e\u5230\u6ee1\u610f\u7684\u89e3\u51b3\u65b9\u6848<br \/>\u76ee\u524d\u662f\u7528\u5f02\u6b65\u961f\u5217\uff0c\u5f53\u6ee1\u8db3\u4e00\u5b9a\u6761\u4ef6\u5c31\u6e05\u7a7a\u961f\u5217\uff0c\u4f46\u6761\u4ef6\u6ee1\u8db3\u65f6\uff0c\u5df2\u7ecf\u5e76\u884c\u542f\u52a8\u7684\u4e0d\u80fd\u53d6\u6d88\uff0c\u8981\u7ee7\u7eed\u5de5\u4f5c\uff0c\u53ea\u662f\u6e05\u7a7a\u4e86\u672a\u542f\u52a8\u7684\u961f\u5217                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058687\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : js8510 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u540c @sujin190 \u3002 \u6211\u731c\u6d4b\u53ef\u80fd\u60f3\u7684\u662f multiprocessing \u800c\u4e0d\u662f asyncio.<br \/>\u5982\u679c pre request\/ post response \u6709 cpu heavy \u7684\u5904\u7406\u3002\u5e76\u53d1\u5012\u662f\u6709\u610f\u4e49\u7684\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5 map_async \u3002\u5982\u679c i\/o \u8fd8\u6ca1\u53d1\u751f\uff0c\u6216\u8005\u5df2\u7ecf\u53d1\u751f\uff0c\u4f60\u53ef\u4ee5 terminate \u6389\u5176\u4ed6 process. \u5982\u679c\u6b63\u5728 i\/o blocking \u4f60\u8fd8\u662f\u8981 wait \u7136\u540e kill \u6389\u3002<\/p>\n<p>\u8fd9\u6837\u8c03\u5ea6\u6709\u5f00\u9500\uff0c\u8981\u5177\u4f53\u5206\u6790\u3002\u3002\u7b80\u5355\u7684 post \u8bf7\u6c42\u5c31\u8fd4\u56de\u5e94\u8be5\u4e0d\u503c\u5f97\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058688\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zeroDev <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u534f\u7a0b\u91cc\u7684 active \u6765\u5224\u65ad                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058689\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zeroDev <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\uff0c\u6211\u611f\u89c9\u5bf9\u4e8e\u4f60\u8fd9\u4e2a\u9700\u6c42\uff0c\u4e0d\u5e94\u8be5\u8fdb\u884c\u5e76\u53d1\u8bf7\u6c42\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5058690\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : muzuiget <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8001\u751f\u5e38\u8c08\uff0c\u4ece\u5916\u90e8\u53d6\u6d88\u76f8\u5f53\u4e8e\u5f3a\u6740\u8fdb\u7a0b\uff0c\u597d\u5bb9\u6613\u9020\u6210\u6570\u636e\u4e00\u81f4\u6027\u95ee\u9898\u3002<\/p>\n<p>\u6b63\u786e\u59ff\u52bf\u5c31\u662f\u7ebf\u7a0b \/\u534f\u7a0b\u81ea\u5df1\u5728\u67d0\u4e9b\u5173\u952e\u70b9\u5224\u65ad\u67d0\u4e2a\u5171\u4eab\u53d8\u91cf\u72b6\u6001\uff0c\u7136\u540e\u81ea\u5df1\u4f18\u96c5\u9000\u51fa\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u4e00\u4e2a\u5173\u4e8e asyncio \u7684\u95ee\u9898&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\/318507"}],"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=318507"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/318507\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318507"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}