{"id":419616,"date":"2021-03-31T18:35:00","date_gmt":"2021-03-31T10:35:00","guid":{"rendered":"http:\/\/4563.org\/?p=419616"},"modified":"2021-03-31T18:35:00","modified_gmt":"2021-03-31T10:35:00","slug":"python3-%e5%a4%9a%e8%bf%9b%e7%a8%8b%e6%b1%82%e5%8a%a9-oserror-errno-24-too-many-open-files","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=419616","title":{"rendered":"python3 \u591a\u8fdb\u7a0b\u6c42\u52a9 OSError: [Errno 24] Too many open files"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  python3 \u591a\u8fdb\u7a0b\u6c42\u52a9 OSError: [Errno 24] Too many open files               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : css3 <\/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>\u4e1a\u52a1\uff1a\u6709\u5927\u91cf(\u672c\u6b21\u6d4b\u8bd5\u65f6 <code>1 <\/code>\u4e07\u591a\u5f20)\u56fe\u7247\u9700\u8981\u8f6c\u6210 <code>base64 <\/code>\u7f16\u7801\u540e\uff0c\u9001\u5165 <code>http<\/code> \u63a5\u53e3\u8bf7\u6c42\u5904\u7406\uff0c\u6211\u91c7\u7528\u4ee5\u4e0b\u4ee3\u7801: <code>base64 <\/code>\u7528\u751f\u6210\u5668\u5904\u7406\uff0c <code>request <\/code>\u7528\u591a\u8fdb\u7a0b\u3002 \u4f46\u4e0b\u9762\u4ee3\u7801\u8dd1\u5230\u4e00\u534a\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u629b\u4e86 <code>OSError: [Errno 24] Too many open files<\/code>\uff0c \u767e\u5ea6\u4e86\u4e00\u4e0b\uff0c\u770b\u4e0a\u53bb\u662f\u8fdb\u7a0b\u8d85\u8fc7\u6240\u80fd\u5f00\u542f\u7684\u6700\u5927\u6587\u4ef6\u6570\u4e86\uff0c <code>ulimit -n # mac 8192<\/code> \u8bf7\u6559\u4e0b\u5404\u4f4d\uff0c\u6211\u600e\u4e48\u5e94\u8be5 <code>fix<\/code> \u8fd9\u4e2a\u95ee\u9898\uff0c\u6700\u7ec8\u9700\u6c42\u5c31\u662f\u60f3\u5feb\u901f\u9ad8\u6548\u7684\u5b8c\u6210\u8fd9\u4e2a\u64cd\u4f5c\uff0c\u53ef\u80fd\u6211\u5199\u7684\u4ee3\u7801\u4e00\u5f00\u59cb\u5c31\u6709\u95ee\u9898\uff0c\u8fd8\u5e0c\u671b\u5927\u4f6c\u4eec\u6307\u70b9\u4e00\u4e0b\u3002<\/p>\n<pre><code>import json import time import requests import base64 import os from multiprocessing import Process     def img_to_base64(img_path):     r = {}     for root, dirs, files in os.walk(img_path):         for pic in files:             if pic.endswith(('.png', '.jpg', '.jpeg', '.tiff', '.bmp', '.gif')):                 img = os.path.join(root, pic)                 with open(img, 'rb') as f:                     bs64 = base64.b64encode(f.read()).decode('utf-8')                     r[img] = bs64                     yield r    def req(host, img_path):     bs64_generator = img_to_base64(img_path)     procs = []      for items in bs64_generator:         body, pic = None, None         for pic, base64 in items.items():             body = {                 \"requests\": [                     {                         \"resource\": {                             \"base64\": base64                         }                     }                 ]             }          p = Process(target=r, args=(host, body, pic))         procs.append(p)         p.start()     for proc in procs:         proc.join()     def r(host, body, img):     url = f'http:\/\/{host}\/demo\/'     r = requests.post(url, data=json.dumps(body))     print(img, r.json().get('results'))     ret = r.json().get('results')[0]['status']     if ret != 'OK':         print(img, ret)     req('10.10.23.17:3345', '.\/mypic\/') <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>32<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5605468\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : BrettD <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ulimit \u4e0d\u884c\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605469\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liprais <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             yield \u90a3\u91cc\u7f29\u8fdb\u4e0d\u5bf9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605470\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CRVV <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1. \u53d1 HTTP \u8bf7\u6c42\u4e0d\u9700\u8981\u7528\u591a\u8fdb\u7a0b<br \/>2. \u5982\u679c\u5728\u4e4e\u6027\u80fd\uff0c\u8bf7\u7528 requests.session<br \/>3. \u5982\u679c\u5355\u7ebf\u7a0b\u987a\u5e8f\u53d1\u8bf7\u6c42\u4e0d\u591f\u5feb\uff0c\u53ef\u4ee5\u7528 ThreadPoolExecutor \u6216\u8005 aiohttp                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605471\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sss495088732 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u505a\u4e2a\u7f13\u51b2\u533a&#8230;.\u8981\u9650\u5236\u4e00\u4e0b\u5e76\u884c\u7684\u8fdb\u7a0b,\u53e5\u67c4\u6570&#8230;\u4f60\u8fd9\u80fd\u8dd1\u5230\u4e00\u534a\u513f,\u90a3\u7535\u8111\u4e5f\u662f\u975e\u5e38\u4e0d\u6233                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605472\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : UN2758 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5b9a\u4e49\u7684 img_to_base64 \u662f\u5355\u7eaf\u7684\u751f\u6210\u5668\uff0c\u60f3\u8981\u534f\u7a0b\u652f\u6301\u7684\u751f\u6210\u5668\uff0c\u5f97\u7ed9\u5b83\u52a0\u4e0a @asyncio.coroutine                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605473\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : UN2758 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @UN2758 #5 \u770b\u9519                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605474\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaolinjia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f00\u4e86 1w \u591a\u8fdb\u7a0b\u725b\u7684\uff0c\u6574\u4e2a multiprocessing.Pool \u8fdb\u7a0b\u6c60\u9650\u5236\u4e0b\u5e76\u884c\u6570\u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605475\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : css3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @BrettD mac 8192 \u8dd1\u6ee1\u4e86<\/p>\n<p>@liprais \u8fd9\u4e2a\u7f29\u8fdb\u5e94\u8be5\u6ca1\u95ee\u9898\u5427\uff0c\u6bcf\u5904\u7406 1 \u5f20\uff0cyield \u51fa\u6765<\/p>\n<p>@CRVV \u4e3a\u5565\u4e0d\u9700\u8981\u7528\u591a\u8fdb\u7a0b\u5462<\/p>\n<p>@sss495088732 \u4e0d\u77e5\u9053\u548b\u641e\u7f13\u51b2\u533a<\/p>\n<p>@UN2758 \u8001\u54e5\u60f3\u8868\u8fbe\u5565\uff0c\u6211\u6ca1\u6709\u770b\u592a\u61c2\u554a<\/p>\n<p>@xiaolinjia \u597d\u7684\uff0c\u591a\u8c22\uff0c\u6211\u627e\u4e0b\u6587\u6863                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605476\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ch2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1 \u4e07\u4e2a\u4efb\u52a1\u6b63\u5e38\u505a\u6cd5\u662f\u7528\u8fdb\u7a0b\u6c60\u5f00 n \u4e2a\u8fdb\u7a0b(n&lt;=\u4f60\u7684 cpu \u6838\u5fc3\u6570*2)<br \/>\u5206\u6279\u9646\u7eed\u5b8c\u6210\uff0c\u800c\u4e0d\u662f 1 \u4e07\u4e2a\u8fdb\u7a0b\u4e00\u62e5\u800c\u4e0a<br \/>\u800c\u4e14\u4f60\u7684\u8fd9\u4e2a\u4ee3\u7801\u74f6\u9888\u5728\u7f51\u901f\u4e0a\uff0c\u6839\u672c\u4e0d\u9700\u8981\u591a\u8fdb\u7a0b\uff0c\u7528\u591a\u7ebf\u7a0b\u5c31\u80fd\u5904\u7406<br \/>\u4f46\u662f\u6700\u4f18\u7684\u505a\u6cd5\u662f\u7528 grequests \u4e00\u6b21\u6279\u91cf\u53d1 1000 \u4e2a\u8bf7\u6c42\uff0c\u914d\u5408\u4e0a\u9519\u8bef\u91cd\u8bd5\uff0c\u5206 10-20 \u6b21\u5c31\u641e\u5b9a\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605477\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ch2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u968f\u4fbf\u627e\u5230\u7f51\u56fe\uff0cgrequests \u662f\u7f16\u7a0b\u6700\u7b80\u5355\u7684\u5927\u6279\u91cf\u53d1 http \u8bf7\u6c42\u7684\u65b9\u6cd5\uff0c\u51e0\u4e4e\u6ca1\u6709\u552f\u4e8c\u7684\u5176\u4ed6\u9009\u62e9\uff0c\u4f60\u4f1a\u7528 requests \u5c31\u4f1a\u7528 grequests<br \/> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/04\/20210401_6065b78661edd.jpg\" rel=\"noreferrer\" referrerpolicy=\"no-referrer\" alt=\"python3 \u591a\u8fdb\u7a0b\u6c42\u52a9 OSError: [Errno 24] Too many open files\"> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605478\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hsfzxjy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @css3 \u4f60\u8981\u7b49\u6587\u4ef6\u5173\u4e86\u518d yield                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605479\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shuax <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f00 100 \u4e2a\u8fdb\u7a0b\u5dee\u4e0d\u591a\u4e86\uff0c\u518d\u591a\u4e5f\u4e0d\u5feb\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605480\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zonyitoo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6bcf\u4e2a\u56fe\u6807\u5355\u72ec\u5f00\u4e00\u4e2a\u8fdb\u7a0b\u53bb\u8dd1\uff0c\u8fd9\u5c45\u7136\u80fd\u8dd1\u5f97\u52a8\u7535\u8111\u7684\u914d\u7f6e\u4e5f\u7740\u5b9e\u5389\u5bb3\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605481\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : renmu123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             hhttp \u76f4\u63a5\u5f00\u4e2a\u8fdb\u7a0b\u6c60\u5c31\u53ef\u4ee5\u4e86\uff0c\u6216\u8005\u7528 grequest \u3002\u57fa\u672c\u90fd\u662f\u5f00\u7bb1\u5373\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605482\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : css3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ch2 \u611f\u8c22\u8001\u54e5\uff0c\u5b66\u4e60\u4e86\uff0c\u6211\u8bd5\u8bd5\u8fd9\u4e2a\u5e93\u3002<br \/>@hsfzxjy\uff0c\u6211\u7684\u7406\u89e3\u662f with \u81ea\u52a8\u4f1a\u5173\u95ed\u5462\uff0c\u53e6\u5916\u6211\u4e5f\u5c1d\u8bd5\u628a yield \u7ed9\u653e\u5230 with \u5916\u8fb9\uff0c\u4e5f\u8fd8\u662f\u8fd9\u4e2a\u95ee\u9898\uff0c\u5e94\u8be5\u4e3b\u8981\u95ee\u9898\u51fa\u5728\u591a\u8fdb\u7a0b\u54ea\u91cc\uff0c\u5982\u540c 13 \u6263\u8001\u54e5\u8bf4\u7684<br \/>@shuax \u55ef\uff0c\u591a\u8c22\u8001\u54e5<br \/>@zonyitoo \u5b66\u4e1a\u4e0d\u7cbe\uff0c\u60ed\u6127<br \/>@renmu123 \u591a\u8c22\uff0c\u6211\u8bd5\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605483\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aladdindingding <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ulimit \u6539\u6210 65535                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605484\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : css3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aladdindingding \u672c\u8d28\u662f\u6211\u8fdb\u7a0b\u548c\u56fe\u7247\u6570\u4e00\u81f4\u4e86\uff0c\u8fd9\u91cc\u6709\u95ee\u9898\uff0c\u6539\u8fd9\u4e2a\u503c\uff0c\u89e3\u51b3\u4e0d\u4e86\u672c\u8d28\u4e0a\u7684\u95ee\u9898\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605485\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8fd9\u4e2a\u9700\u6c42 py \u7684\u6700\u4f73\u5b9e\u8df5\u5e94\u8be5\u662f\u591a\u7ebf\u7a0b ffi \u52a0\u5f02\u6b65 io\uff0c\u5927\u6982\u4f1a\u6bd4\u4f60\u73b0\u5728\u7684\u65b9\u6848\u5feb\u5f88\u591a\u5f88\u591a\u5f88\u591a\u5f88\u591a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605486\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : laqow <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u8d77\u6765\u662f 2 \u7684\u95ee\u9898\uff0cyield \u5199 with \u91cc\u9762\u4e86\uff0c\u6bcf\u6b21\u8fed\u4ee3\u6587\u4ef6\u90fd\u6ca1\u5173<\/p>\n<p>\u4e0d\u6539\u7a0b\u5e8f\u7684\u8bdd\u7528 linux\uff0c\u60f3\u5f00\u591a\u5c11\u6587\u4ef6\u5f00\u591a\u5c11                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605487\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : laqow <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u611f\u89c9\u8fd9\u6837\u5199\u6bcf\u4e2a\u56fe\u90fd\u662f\u4e3b\u8fdb\u7a0b\u5f00\u7684\uff0c\u8fd8\u6ca1\u8fdb worker \u5c31\u5df2\u7ecf\u9519\u8bef\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605488\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : css3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @laqow \u6211\u628a yield \u653e\u5230 with \u5916\uff0c\u4e5f\u662f\u8dd1\u4e00\u534a OSError: [Errno 24] Too many open files\uff0c \u653e linux \u670d\u52a1\u5668\u4e0a\u8dd1\uff0c\u8dd1\u7684\u65f6\u95f4\u4e45\u70b9\u513f\uff0c\u6700\u7ec8\u4e5f\u4f1a OSError: [Errno 24] Too many open files                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605489\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @css3 \u8ddf yield \u6ca1\u6709\u5173\u7cfb\uff0cyield \u53ea\u662f\u8d77\u5230\u4fdd\u5b58\u72b6\u6001\u4e2d\u65ad\u6267\u884c\u7684\u4f5c\u7528\uff0c\u4f60\u5728\u5faa\u73af\u91cc\u6bcf\u6b21\u8fed\u4ee3\uff0c\u751f\u6210\u5668\u4e5f\u5faa\u73af\uff0cwith \u7ba1\u7406\u5668\u662f\u6b63\u5e38\u7ed3\u675f\u7684\u3002\u53e6\u5916\u4ed4\u7ec6\u770b\u4e86\u4e00\u4e0b\u4f60\u7684\u4ee3\u7801\uff0c\u4f60\u7684\u591a\u8fdb\u7a0b\u4f3c\u4e4e\u4ec5\u8d1f\u8d23\u7f51\u7edc\u901a\u4fe1\uff0c\u8fd9\u662f\u975e\u5e38\u4e0d\u5408\u7406\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5efa\u8bae\u4e86\u89e3 python \u4e2d\u7684\u5f02\u6b65\u7f51\u7edc\u901a\u4fe1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605490\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LeeReamond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @LeeReamond \u4f60\u6bcf\u65b0\u5efa\u8fdb\u7a0b\uff0c\u7cfb\u7edf\u8981\u5f00\u8f9f\u4e13\u95e8\u7684\u6587\u4ef6\u6307\u6807\u6307\u5411\u8f93\u5165\u8f93\u51fa\u6d41\uff0c\u800c\u8fdb\u7a0b\u5185\u90e8\u53c8\u4e3a\u7f51\u7edc\u8bbf\u95ee\u5f00\u8f9f\u4e86\u4e13\u95e8\u7684\u6587\u4ef6\u3002\u4e14 tcp \u8bbf\u95ee\u540e\u6709 timewait \u72b6\u6001\uff0c\u5360\u7528\u6587\u4ef6\u4e0d\u4f1a\u7acb\u5373\u88ab\u91ca\u653e\uff0c\u5bfc\u81f4\u4f60\u7684\u8d44\u6e90\u5403\u6ee1\u3002\u73b0\u4ee3\u670d\u52a1\u5668\u5355\u673a\u6bcf\u79d2\u53ef\u4ee5\u5904\u7406\u51e0\u5341\u4e07\u4e2a\u8bf7\u6c42\uff0c\u5373\u4f7f\u7528 python \u4e5f\u4e00\u6837\uff0c\u7edd\u4e0d\u662f\u4f60\u8fd9\u4ec5\u4ec5\u4e00\u4e07\u4e2a\u4e0d\u73b0\u5b9e\u8bf7\u6c42\u80fd\u641e\u5d29\u7684\u3002\u4e00\u4e2a\u7b80\u5355\u7684\u591a\u8bbf\u95ee\u95ee\u9898\u88ab\u4f60\u641e\u6210\u8fd9\u6837\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605491\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mjawp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u79cd\u4e1a\u52a1\u9700\u6c42\u5e94\u8be5\u662f\u591a\u7ebf\u7a0b\u6bd4\u8f83\u597d\u5427\uff1f<\/p>\n<p>1.\u591a\u8fdb\u7a0b\u5207\u6362\u5f00\u9500\u6bd4\u591a\u7ebf\u7a0b\u5207\u6362\u5f00\u9500\u5927<br \/>2.\u5408\u7406\u7684\u8fdb\u7a0b\u6570\u5e94\u8be5\u662f\u7b49\u4e8e\u4f60\u7684 cpu \u6838\u5fc3\u6570<br \/>3.\u901f\u5ea6\u74f6\u9888\u4e3b\u8981\u8fd8\u662f\u7b49\u5f85\u8bf7\u6c42\u548c IO\uff0c\u6240\u4ee5\u5728\u7b49\u5f85 IO \u4e0e\u7f51\u7edc\u8bf7\u6c42\u7684\u65f6\u5019\u53ef\u4ee5\u5207\u6362\u5f88\u591a\u5f88\u591a\u4e0d\u540c\u7684\u7ebf\u7a0b\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605492\" 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>                                                             @liprais #2 \u8bf4\u7684\u662f\u5173\u952e\u70b9<br \/>\u4e0d\u8981\u5728 with open \u91cc\u9762 yield<br \/>yield \u76f8\u5f53\u4e8e\u751f\u6210\u5668\uff0c\u6570\u636e\u662f\u96c6\u4e2d\u5904\u7406\u7684\uff0c\u4e0d\u662f\u9010\u4e2a\u5904\u7406\uff0c\u8fd9\u5c31\u9020\u6210\u6253\u5f00\u592a\u591a<br \/>\u7b80\u5355\u8bf4\u5c31\u662f\u5168\u90e8 yield \u7684\u6570\u636e \u90fd \u83b7\u53d6\u540e\u96c6\u4e2d\u624d\u5904\u7406\uff0c\u8fd9\u65f6\u6bcf\u4e2a open \u90fd\u6ca1\u6709 close                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605493\" 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>                                                             \u524d\u7f6e\u91cd\u70b9\uff1a\u770b\u4e0b\u9762\u7b2c\u56db\u70b9<\/p>\n<p>\u6211\u505a\u8fc7\u7c7b\u4f3c\u7684\uff0c\u4e0d\u8fc7\u4e0d\u662f base64\uff0c\u800c\u662f CRC32\uff0c\u5e94\u8be5\u6bd4 base64 \u8017\u65f6\uff0c8K \u5f20\u56fe\u7247<br \/>\u5efa\u8bae\uff1a<br \/>1. base64 \u79fb\u51fa os.walk\uff0c\u540c\u65f6\u4e5f\u5efa\u8bae os.scandir \u66ff\u6362 walk\uff0c\u9012\u5f52\u53ea yield \u8fd4\u56de\u8def\u5f84\u5c31\u597d\u4e86<br \/>2. \u591a\u8fdb\u7a0b\u53ef\u4ee5\u5c1d\u8bd5\u6362\u6210 Pool+Pool.imap()\uff0c\u6ce8\u610f\u8981\u7528 close()\uff0c\u53c2\u8003\u624b\u518c\uff0cPool.close \u8981\u5728 Pool.join \u524d\u9762\uff0c\u540c\u65f6\u9650\u5236\u7ebf\u7a0b\u6570\u91cf<br \/>3. \u5c0f\u95ee\u9898\uff0c\u6269\u5c55\u540d\u5217\u8868\u53ea\u6709\u5c0f\u5199\uff0c\u4f60\u786e\u4fdd\u4e00\u4e07\u591a\u6587\u4ef6\u6269\u5c55\u540d\u90fd\u6ca1\u6709\u5927\u5199\u5b57\u6bcd\u4e48\uff1f\u4e0d\u5c0f\u5fc3\u4f1a\u6f0f\u6389\u6587\u4ef6\u7684<br \/>4. \u6700\u540e\u662f\u4e25\u91cd\u7684\u903b\u8f91\u9519\u8bef\uff0cimg_to_base64 \u91cc\u9762\u7684 r \u662f\u4e2a\u5b57\u5178\uff0c\u4f60\u6700\u540e return \u4e00\u6b21\u5c31\u591f\u4e86\uff0c\u600e\u4e48\u662f\u4e0d\u505c yield \u8fd9\u4e2a\u5b57\u5178\u5462\uff1f\u6211\u89c9\u5f97\u8fd9\u662f\u6700\u5927\u95ee\u9898<\/p>\n<p>\u6211\u4ee5\u524d\u8003\u8651\u662f\u904d\u5386\u7684\u540c\u65f6\u5904\u7406\u6587\u4ef6\uff0c\u8fd8\u662f\u904d\u5386\u4e86\u8def\u5f84\u518d\u5904\u7406\u6587\u4ef6\uff0c\u540e\u6765\u6211\u770b\u5230\u904d\u5386\u6811\u662f\u9012\u5f52+yield\uff0c\u5c31\u4e0d\u7ea0\u7ed3\u4e86<br \/>\u9012\u5f52\u91cc\u9762\u5904\u7406\u6587\u4ef6\uff0c\u5904\u7406\u6587\u4ef6 yield \u7ed3\u679c\uff0c\u8fd9\u4e24\u4e2a\u90fd\u4e0d\u662f\u597d\u60f3\u6cd5\uff0c\u80af\u5b9a\u6709\u8bf4\u4e0d\u6e05\u7684\u95ee\u9898\uff08\u56e0\u4e3a python \u662f\u8c03\u7528\u7cfb\u7edf API \u6253\u5f00\u6587\u4ef6\u7684\uff09\uff0c\u6240\u4ee5\u76f4\u63a5\u5c31\u7528\u9012\u5f52 yield \u8def\u5f84\uff0c\u7136\u540e\u518d\u8003\u8651\u5176\u4ed6\u65b9\u5f0f\u4f18\u5316\u6587\u4ef6\u5904\u7406                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605494\" 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>                                                             \u8865\u5145\uff1a\u4f60\u8fd9\u6837\u91cd\u590d yield \u8fd9\u4e2a\u5b57\u5178\uff0c\u91cc\u9762\u8fd8\u6709 open\uff0c\u8fd9\u6837\u4e0d\u662f\u6253\u5f00\u4e00\u4e07\u6b21\uff08\u6bcf\u6587\u4ef6\u4e00\u6b21\uff09\uff0c\u800c\u662f\u6253\u5f00\u4e00\u4e07\u6b21\u7684\u9636\u4e58\uff01\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605495\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b57\u5178\u8fd8\u80fd yield \uff1f\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605496\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : slidoooor <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b66\u4e60\u4e86\uff0c\u611f\u8c22\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605497\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : itwhat <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             IO \u5bc6\u96c6\u578b\u5e94\u8003\u8651\u591a\u7ebf\u7a0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605498\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : css3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @itwhat \u8bf7\u6559\u4e0b\uff0c\u56fe\u7247\u8f6c base64 \u4ec5\u4ec5\u662f IO \u5bc6\u96c6\u578b\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5605499\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : maybedk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             r \u90a3\u4e2a\u5b57\u5178\u6ca1\u5fc5\u8981\u76f4\u63a5 yield (img,bs64),\u4e0e with \u5bf9\u9f50;<br \/>\u5f00\u8fdb\u7a0b\u6c60 pool = multiprocessing.Pool(4);<br \/>\u57fa\u672c\u80fd\u8dd1\u8d77\u6765\uff0c\u901f\u5ea6\u591a\u5feb\u4e0d\u77e5\u9053                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>python3 \u591a\u8fdb\u7a0b\u6c42\u52a9 OSE&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\/419616"}],"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=419616"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419616\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=419616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=419616"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=419616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}