{"id":79,"date":"2026-05-18T18:36:30","date_gmt":"2026-05-18T10:36:30","guid":{"rendered":"https:\/\/www.devfm.cn\/?p=79"},"modified":"2026-05-18T18:36:30","modified_gmt":"2026-05-18T10:36:30","slug":"%e7%ba%bf%e7%a8%8b%e6%b1%a0","status":"publish","type":"post","link":"https:\/\/www.devfm.cn\/?p=79","title":{"rendered":"\u7ebf\u7a0b\u6c60"},"content":{"rendered":"<pre><code class=\"language-python line-numbers\">import time\nimport threading\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\nimport _thread\nimport demo_requests\nimport asyncio\n\n\ndef task(task_id):\n    for run_count in range(5):\n        print(f\"id: {task_id} run times: {run_count}\")\n        time.sleep(3)\n\ndef handle_result(future):  \n    print(future)  \n    pass\n\nasync def handle():\n    print('handle')\n    pass\n\ndef start_multi_thread(threadPoolNum, count):\n    pool = ThreadPoolExecutor(max_workers=threadPoolNum)\n    futures = []\n    for i in range(count):\n        future = pool.submit(task, i)\n        futures.append(future)\n    print(len(futures))\n    for future in as_completed(futures):\n        print(\"for each futures start\")\n        future.add_done_callback(handle_result)\n        print(\"for each futures end\")\n    pool.shutdown()\n\nif __name__ == '__main__':\n    # start_multi_thread(5, 10)\n    # print('done')\n    t = _thread.start_new_thread(asyncio.run, [handle()])\n    print(t)\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import time import threading from concurrent.futures im&hellip; <a class=\"read-more-link\" href=\"https:\/\/www.devfm.cn\/?p=79\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":1,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions\/80"}],"wp:attachment":[{"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devfm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}