{"id":205110,"date":"2025-05-29T08:07:44","date_gmt":"2025-05-29T00:07:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205110\/"},"modified":"2025-05-29T08:07:44","modified_gmt":"2025-05-29T00:07:44","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%a4%9a%e7%ba%bf%e7%a8%8b%e5%b9%b6%e8%a1%8c%e5%a4%84%e7%90%86%e5%88%97%e8%a1%a8%e9%87%8c%e7%9a%84%e5%ad%97%e5%85%b8%e5%8f%82%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205110\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u5217\u8868\u91cc\u7684\u5b57\u5178\u53c2\u6570\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u5217\u8868\u91cc\u7684\u5b57\u5178\u53c2\u6570\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u4f7f\u7528\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u5217\u8868\u91cc\u7684\u5b57\u5178\u53c2\u6570\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323715086741e4340fa35.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5982\u4f55\u4f7f\u7528\u591a\u7ebf\u7a0b\u5904\u7406\u5217\u8868\u4e2d\u5b57\u5178\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570<\/p>\n<p><strong>\u95ee\u9898\u80cc\u666f<\/strong><\/p>\n<p>\u62e5\u6709\u5927\u91cf\u5b57\u5178\u53c2\u6570\u7684\u5217\u8868\uff0c\u9700\u8981\u9010\u4e2a\u4f20\u9012\u7ed9dosome(ip, password, user_name)\u51fd\u6570\u5e76\u8fd0\u884c\u3002\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6570\u91cf\uff0c\u4f8b\u5982\uff0c\u4ee5 2 \u4e3a\u5355\u4f4d\u5e76\u53d1\u6267\u884c\u53c2\u6570\u4f20\u9012\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u91c7\u7528threadpoolexecutor\u7ebf\u7a0b\u6c60\u5b9e\u73b0\u591a\u7ebf\u7a0b\u5904\u7406\uff1a<\/p>\n<pre>import time\nfrom concurrent.futures import ThreadPoolExecutor\nimport threading\n\nmy_list = [\n    {'ip': '192.168.1.2', 'password': '123456', 'user_name': '654321'},\n    {'ip': '192.168.1.3', 'password': '123456', 'user_name': '654321'},\n    {'ip': '192.168.1.4', 'password': '123456', 'user_name': '654321'},\n    {'ip': '192.168.1.5', 'password': '123456', 'user_name': '654321'},\n    {'ip': '192.168.1.6', 'password': '123456', 'user_name': '654321'}\n]\n\ndef dosome(ip, password, user_name):\n    tname = threading.current_thread().getName()\n    time.sleep(1)\n    print(f'{tname} {ip}')\n\ntpe = ThreadPoolExecutor(max_workers=3)\n\nfor m in my_list:\n    tpe.submit(dosome, **m)<\/pre>\n<p><strong>\u6267\u884c\u6d41\u7a0b<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a threadpoolexecutor\uff0c\u5e76\u8bbe\u7f6e\u6700\u5927\u5de5\u4f5c\u7ebf\u7a0b\u6570\u3002<\/li>\n<li>\u904d\u5386\u5b57\u5178\u53c2\u6570\u5217\u8868\u3002<\/li>\n<li>\u4f7f\u7528 submit() \u65b9\u6cd5\u6dfb\u52a0\u4efb\u52a1\u5230\u7ebf\u7a0b\u6c60\uff0c\u540c\u65f6\u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26\uff08**m\uff09\u5c06\u5b57\u5178\u4e2d\u7684\u952e\u503c\u5bf9\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u3002<\/li>\n<li>\u5f53\u7ebf\u7a0b\u5b8c\u6210\u4efb\u52a1\u540e\uff0c\u4f1a\u6253\u5370\u7ebf\u7a0b\u540d\u79f0\u548c ip \u5730\u5740\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u5217\u8868\u91cc\u7684\u5b57\u5178\u53c2\u6570\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528\u591a\u7ebf\u7a0b\u5e76\u884c\u5904\u7406\u5217\u8868\u91cc\u7684\u5b57&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205110","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205110"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205110\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}