{"id":205339,"date":"2025-05-29T11:24:14","date_gmt":"2025-05-29T03:24:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205339\/"},"modified":"2025-05-29T11:24:14","modified_gmt":"2025-05-29T03:24:14","slug":"python%e8%84%9a%e6%9c%ac%e5%a6%82%e4%bd%95%e6%b8%85%e7%a9%ba%e7%bb%88%e7%ab%af%e4%b9%8b%e5%89%8d%e7%9a%84%e8%be%93%e5%87%ba%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205339\/","title":{"rendered":"Python\u811a\u672c\u5982\u4f55\u6e05\u7a7a\u7ec8\u7aef\u4e4b\u524d\u7684\u8f93\u51fa\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python\u811a\u672c\u5982\u4f55\u6e05\u7a7a\u7ec8\u7aef\u4e4b\u524d\u7684\u8f93\u51fa\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/17328595076749567313a83.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u56fe\u6240\u793a\uff0cpython\u811a\u672c\u5982\u4f55\u6e05\u7a7a\u4e4b\u524d\u7684\u8f93\u51fa\u5230\u5149\u6807\u4f4d\u7f6e\uff1f<\/strong><\/p>\n<p>\u5728\u7ec8\u7aef\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u6e05\u9664\u6307\u5b9a\u533a\u57df\u7684\u8f93\u51fa\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b9e\u73b0\uff1a<\/p>\n<pre>import sys\n\n# \u6e05\u9664\u5149\u6807\u6240\u5728\u884c\u4e4b\u524d\u7684\u6240\u6709\u884c\nsys.stdout.write(\"\\033[1a\\033[2k\")<\/pre>\n<p>\u6b64\u5904\uff0cansi\u8f6c\u4e49\u5e8f\u5217 &#8221; 33[1a&#8221; \u5c06\u5149\u6807\u5411\u4e0a\u79fb\u52a8\u4e00\u884c\uff0c\u800c &#8221; 33[2k&#8221; \u7528\u4e8e\u6e05\u9664\u5149\u6807\u6240\u5728\u884c\u3002\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u9488\u5bf9\u7279\u5b9a\u884c\u6e05\u9664\u8f93\u51fa\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u53ef\u5229\u7528\u7ebf\u7a0b\u6c60\u6765\u5728\u540e\u53f0\u6267\u884c\u5b9a\u65f6\u4efb\u52a1\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>import time\nimport threading\n\n# \u5728\u540e\u53f0\u6bcf\u79d2\u8fd0\u884c\u4e00\u6b21\u6307\u5b9a\u51fd\u6570\ndef background_task():\n    while True:\n        print(\"\u540e\u53f0\u4efb\u52a1\u6b63\u5728\u8fd0\u884c\")\n        time.sleep(1)\n\n# \u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6c60\npool = ThreadPoolExecutor(max_workers=1)\n\n# \u5728\u540e\u53f0\u8fd0\u884c\u6307\u5b9a\u51fd\u6570\npool.submit(background_task)<\/pre>\n<p>\u6b64\u65f6\uff0c\u540e\u53f0\u4efb\u52a1\u5c06\u5728\u65b0\u7ebf\u7a0b\u4e2d\u6267\u884c\u4e14\u4e0d\u53d7\u4e3b\u7ebf\u7a0b\u5f71\u54cd\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aPython\u811a\u672c\u5982\u4f55\u6e05\u7a7a\u7ec8\u7aef\u4e4b\u524d\u7684\u8f93\u51fa\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u811a\u672c\u5982\u4f55\u6e05\u7a7a\u7ec8\u7aef\u4e4b\u524d&#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-205339","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205339","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=205339"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205339\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}