{"id":1001507,"date":"2024-12-27T10:00:55","date_gmt":"2024-12-27T02:00:55","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1001507.html"},"modified":"2024-12-27T10:00:58","modified_gmt":"2024-12-27T02:00:58","slug":"python%e4%bb%a3%e7%a0%81%e5%a6%82%e4%bd%95%e6%9d%80%e6%ad%bb%e7%ba%bf%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1001507.html","title":{"rendered":"python\u4ee3\u7801\u5982\u4f55\u6740\u6b7b\u7ebf\u7a0b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075649\/5b650129-9b81-4a99-8b81-4a5e9a985099.webp\" alt=\"python\u4ee3\u7801\u5982\u4f55\u6740\u6b7b\u7ebf\u7a0b\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u6740\u6b7b\u7ebf\u7a0b\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\u3001\u4f7f\u7528\u5b88\u62a4\u7ebf\u7a0b\u3001\u4f7f\u7528\u7ebf\u7a0b\u6c60\u3001\u5229\u7528\u7b2c\u4e09\u65b9\u5e93\u3002<\/strong>\u672c\u6587\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\uff0c\u5373\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\u7684\u65b9\u6cd5\uff0c\u5e76\u4ecb\u7ecd\u5176\u4ed6\u53ef\u9009\u65b9\u6848\u7684\u5b9e\u73b0\u7ec6\u8282\u53ca\u5176\u4f18\u7f3a\u70b9\uff0c\u4ee5\u5e2e\u52a9\u8bfb\u8005\u6839\u636e\u81ea\u8eab\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u7ebf\u7a0b\u7ec8\u6b62\u7b56\u7565\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\u662fPython\u4e2d\u8f83\u5e38\u89c1\u7684\u4e00\u79cd\u7ec8\u6b62\u7ebf\u7a0b\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8bbe\u7f6e\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\uff0c\u7ebf\u7a0b\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u5b9a\u671f\u68c0\u67e5\u8be5\u6807\u5fd7\u7684\u72b6\u6001\uff0c\u5982\u679c\u53d1\u73b0\u6807\u5fd7\u88ab\u8bbe\u7f6e\u4e3a\u7ec8\u6b62\u6761\u4ef6\uff0c\u5219\u7ebf\u7a0b\u4f1a\u4e3b\u52a8\u9000\u51fa\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9e\u73b0\u6b65\u9aa4<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u4f5c\u4e3a\u7ebf\u7a0b\u7684\u8fd0\u884c\u6807\u5fd7\u3002\u5728\u7ebf\u7a0b\u7684\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u5b9a\u671f\u68c0\u67e5\u8be5\u6807\u5fd7\u7684\u72b6\u6001\u3002\u5982\u679c\u6807\u5fd7\u88ab\u8bbe\u7f6e\u4e3a\u7ec8\u6b62\u6761\u4ef6\uff0c\u5219\u901a\u8fc7return\u8bed\u53e5\u6216break\u8bed\u53e5\u9000\u51fa\u7ebf\u7a0b\u7684\u6267\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>import time<\/p>\n<h2><strong>\u5b9a\u4e49\u5168\u5c40\u53d8\u91cf<\/strong><\/h2>\n<p>stop_thread = False<\/p>\n<p>def worker():<\/p>\n<p>    while not stop_thread:<\/p>\n<p>        print(&quot;\u7ebf\u7a0b\u8fd0\u884c\u4e2d...&quot;)<\/p>\n<p>        time.sleep(1)<\/p>\n<p>    print(&quot;\u7ebf\u7a0b\u5df2\u7ec8\u6b62&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u7ebf\u7a0b<\/strong><\/h2>\n<p>t = threading.Thread(target=worker)<\/p>\n<p>t.start()<\/p>\n<h2><strong>\u8ba9\u7ebf\u7a0b\u8fd0\u884c\u51e0\u79d2\u949f<\/strong><\/h2>\n<p>time.sleep(5)<\/p>\n<h2><strong>\u7ec8\u6b62\u7ebf\u7a0b<\/strong><\/h2>\n<p>stop_thread = True<\/p>\n<h2><strong>\u7b49\u5f85\u7ebf\u7a0b\u7ed3\u675f<\/strong><\/h2>\n<p>t.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u7f3a\u70b9\u5206\u6790<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\u7684\u65b9\u6cd5\u7b80\u5355\u6613\u884c\uff0c\u9002\u5408\u7528\u4e8e\u63a7\u5236\u903b\u8f91\u76f8\u5bf9\u7b80\u5355\u7684\u7ebf\u7a0b\u3002\u4f46\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u8981\u6c42\u7ebf\u7a0b\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u5b9a\u671f\u68c0\u67e5\u6807\u5fd7\u72b6\u6001\uff0c\u56e0\u6b64\u5bf9\u7ebf\u7a0b\u7684\u903b\u8f91\u8bbe\u8ba1\u6709\u4e00\u5b9a\u8981\u6c42\u3002\u6b64\u5916\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5e76\u4e0d\u80fd\u7acb\u5373\u7ec8\u6b62\u7ebf\u7a0b\uff0c\u800c\u662f\u8981\u7b49\u5230\u7ebf\u7a0b\u4e0b\u6b21\u68c0\u67e5\u6807\u5fd7\u65f6\u624d\u4f1a\u7ec8\u6b62\uff0c\u56e0\u6b64\u53ef\u80fd\u4f1a\u6709\u5ef6\u8fdf\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5b88\u62a4\u7ebf\u7a0b<\/p>\n<\/p>\n<p><p>\u5b88\u62a4\u7ebf\u7a0b\u662f\u6307\u5728\u4e3b\u7ebf\u7a0b\u7ed3\u675f\u540e\u81ea\u52a8\u7ec8\u6b62\u7684\u7ebf\u7a0b\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u7ebf\u7a0b\u7684daemon\u5c5e\u6027\u6765\u5b9e\u73b0\u5b88\u62a4\u7ebf\u7a0b\u3002\u5f53\u4e3b\u7ebf\u7a0b\u7ed3\u675f\u65f6\uff0c\u6240\u6709\u5b88\u62a4\u7ebf\u7a0b\u4f1a\u81ea\u52a8\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9e\u73b0\u6b65\u9aa4<\/strong><\/p>\n<\/p>\n<p><p>\u521b\u5efa\u7ebf\u7a0b\u65f6\uff0c\u5c06\u5176daemon\u5c5e\u6027\u8bbe\u7f6e\u4e3aTrue\u3002\u8fd9\u6837\uff0c\u5f53\u4e3b\u7ebf\u7a0b\u7ed3\u675f\u65f6\uff0c\u5b88\u62a4\u7ebf\u7a0b\u4f1a\u81ea\u52a8\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>import time<\/p>\n<p>def worker():<\/p>\n<p>    while True:<\/p>\n<p>        print(&quot;\u5b88\u62a4\u7ebf\u7a0b\u8fd0\u884c\u4e2d...&quot;)<\/p>\n<p>        time.sleep(1)<\/p>\n<h2><strong>\u521b\u5efa\u5b88\u62a4\u7ebf\u7a0b<\/strong><\/h2>\n<p>t = threading.Thread(target=worker)<\/p>\n<p>t.daemon = True<\/p>\n<p>t.start()<\/p>\n<h2><strong>\u8ba9\u4e3b\u7ebf\u7a0b\u8fd0\u884c\u51e0\u79d2\u949f<\/strong><\/h2>\n<p>time.sleep(5)<\/p>\n<p>print(&quot;\u4e3b\u7ebf\u7a0b\u7ed3\u675f&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u7f3a\u70b9\u5206\u6790<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u5b88\u62a4\u7ebf\u7a0b\u7684\u65b9\u6cd5\u7b80\u5355\u4e14\u6709\u6548\uff0c\u9002\u7528\u4e8e\u9700\u8981\u7ebf\u7a0b\u4e0e\u4e3b\u7ebf\u7a0b\u751f\u547d\u5468\u671f\u4e00\u81f4\u7684\u573a\u666f\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5b88\u62a4\u7ebf\u7a0b\u4e0d\u80fd\u4fdd\u8bc1\u8d44\u6e90\u7684\u5b8c\u6574\u91ca\u653e\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5728\u4e3b\u7ebf\u7a0b\u7ed3\u675f\u65f6\u7acb\u5373\u88ab\u7ec8\u6b62\u3002\u56e0\u6b64\uff0c\u5982\u679c\u7ebf\u7a0b\u4e2d\u6709\u9700\u8981\u5173\u95ed\u7684\u6587\u4ef6\u6216\u8005\u9700\u8981\u4fdd\u5b58\u7684\u72b6\u6001\uff0c\u5e94\u8be5\u907f\u514d\u4f7f\u7528\u5b88\u62a4\u7ebf\u7a0b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528\u7ebf\u7a0b\u6c60<\/p>\n<\/p>\n<p><p>\u7ebf\u7a0b\u6c60\u662f\u4e00\u79cd\u7528\u4e8e\u7ba1\u7406\u591a\u4e2a\u7ebf\u7a0b\u7684\u673a\u5236\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7concurrent.futures\u6a21\u5757\u5b9e\u73b0\u7ebf\u7a0b\u6c60\u3002\u901a\u8fc7\u7ebf\u7a0b\u6c60\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u63a7\u5236\u7ebf\u7a0b\u7684\u542f\u52a8\u548c\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9e\u73b0\u6b65\u9aa4<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528concurrent.futures.ThreadPoolExecutor\u521b\u5efa\u7ebf\u7a0b\u6c60\uff0c\u5e76\u63d0\u4ea4\u4efb\u52a1\u3002\u5728\u9700\u8981\u7ec8\u6b62\u7ebf\u7a0b\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u53d6\u6d88\u672a\u5b8c\u6210\u7684\u4efb\u52a1\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from concurrent.futures import ThreadPoolExecutor<\/p>\n<p>import time<\/p>\n<p>def worker():<\/p>\n<p>    while True:<\/p>\n<p>        print(&quot;\u7ebf\u7a0b\u6c60\u4e2d\u7684\u7ebf\u7a0b\u8fd0\u884c\u4e2d...&quot;)<\/p>\n<p>        time.sleep(1)<\/p>\n<h2><strong>\u521b\u5efa\u7ebf\u7a0b\u6c60<\/strong><\/h2>\n<p>with ThreadPoolExecutor(max_workers=1) as executor:<\/p>\n<p>    future = executor.submit(worker)<\/p>\n<p>    # \u8ba9\u7ebf\u7a0b\u8fd0\u884c\u51e0\u79d2\u949f<\/p>\n<p>    time.sleep(5)<\/p>\n<p>    # \u53d6\u6d88\u4efb\u52a1<\/p>\n<p>    future.cancel()<\/p>\n<p>print(&quot;\u7ebf\u7a0b\u6c60\u5173\u95ed&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u7f3a\u70b9\u5206\u6790<\/strong><\/p>\n<\/p>\n<p><p>\u7ebf\u7a0b\u6c60\u53ef\u4ee5\u9ad8\u6548\u5730\u7ba1\u7406\u591a\u4e2a\u7ebf\u7a0b\uff0c\u5e76\u63d0\u4f9b\u4e86\u53d6\u6d88\u672a\u5b8c\u6210\u4efb\u52a1\u7684\u529f\u80fd\u3002\u7136\u800c\uff0c\u7ebf\u7a0b\u6c60\u5e76\u4e0d\u80fd\u7acb\u5373\u7ec8\u6b62\u6b63\u5728\u6267\u884c\u7684\u4efb\u52a1\uff0c\u53ea\u80fd\u53d6\u6d88\u5c1a\u672a\u5f00\u59cb\u7684\u4efb\u52a1\u3002\u56e0\u6b64\uff0c\u5bf9\u4e8e\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u4efb\u52a1\uff0c\u7ebf\u7a0b\u6c60\u7684\u53d6\u6d88\u529f\u80fd\u53ef\u80fd\u4e0d\u592a\u9002\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5229\u7528\u7b2c\u4e09\u65b9\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86Python\u6807\u51c6\u5e93\u4e2d\u7684\u529f\u80fd\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u7528\u4e8e\u66f4\u7075\u6d3b\u5730\u7ba1\u7406\u7ebf\u7a0b\u3002\u4f8b\u5982\uff0cpython-killable-threads\u5e93\u53ef\u4ee5\u5b9e\u73b0\u66f4\u5f3a\u5927\u7684\u7ebf\u7a0b\u7ec8\u6b62\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9e\u73b0\u6b65\u9aa4<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528python-killable-threads\u5e93\uff0c\u53ef\u4ee5\u521b\u5efa\u53ef\u7ec8\u6b62\u7684\u7ebf\u7a0b\uff0c\u5e76\u901a\u8fc7\u8c03\u7528\u5176terminate()\u65b9\u6cd5\u6765\u7ec8\u6b62\u7ebf\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>from killable_thread import KillableThread<\/p>\n<p>def worker():<\/p>\n<p>    while True:<\/p>\n<p>        print(&quot;\u53ef\u7ec8\u6b62\u7ebf\u7a0b\u8fd0\u884c\u4e2d...&quot;)<\/p>\n<p>        time.sleep(1)<\/p>\n<h2><strong>\u521b\u5efa\u53ef\u7ec8\u6b62\u7ebf\u7a0b<\/strong><\/h2>\n<p>t = KillableThread(target=worker)<\/p>\n<p>t.start()<\/p>\n<h2><strong>\u8ba9\u7ebf\u7a0b\u8fd0\u884c\u51e0\u79d2\u949f<\/strong><\/h2>\n<p>time.sleep(5)<\/p>\n<h2><strong>\u7ec8\u6b62\u7ebf\u7a0b<\/strong><\/h2>\n<p>t.terminate()<\/p>\n<p>print(&quot;\u53ef\u7ec8\u6b62\u7ebf\u7a0b\u7ed3\u675f&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u7f3a\u70b9\u5206\u6790<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u63d0\u4f9b\u66f4\u5f3a\u5927\u7684\u529f\u80fd\u548c\u66f4\u7075\u6d3b\u7684\u7ba1\u7406\u65b9\u5f0f\u3002\u7136\u800c\uff0c\u5f15\u5165\u7b2c\u4e09\u65b9\u5e93\u53ef\u80fd\u4f1a\u589e\u52a0\u9879\u76ee\u7684\u590d\u6742\u6027\uff0c\u5e76\u5e26\u6765\u6f5c\u5728\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u4f7f\u7528\u65f6\u9700\u8981\u6743\u8861\u9879\u76ee\u7684\u9700\u6c42\u548c\u590d\u6742\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPython\u4e2d\u7ec8\u6b62\u7ebf\u7a0b\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6848\u3002\u5bf9\u4e8e\u7b80\u5355\u7684\u7ebf\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\u6216\u5b88\u62a4\u7ebf\u7a0b\u7684\u65b9\u6cd5\uff1b\u5bf9\u4e8e\u9700\u8981\u7ba1\u7406\u591a\u4e2a\u7ebf\u7a0b\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u7ebf\u7a0b\u6c60\uff1b\u5bf9\u4e8e\u9700\u8981\u66f4\u5f3a\u5927\u529f\u80fd\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u5f15\u5165\u7b2c\u4e09\u65b9\u5e93\u3002\u5e0c\u671b\u672c\u6587\u7684\u4ecb\u7ecd\u80fd\u591f\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u4e2d\u7684\u7ebf\u7a0b\u7ba1\u7406\u6280\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5b89\u5168\u5730\u7ec8\u6b62\u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u76f4\u63a5\u6740\u6b7b\u7ebf\u7a0b\u5e76\u4e0d\u662f\u63a8\u8350\u7684\u505a\u6cd5\uff0c\u56e0\u4e3a\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8d44\u6e90\u6cc4\u9732\u6216\u6570\u636e\u4e0d\u4e00\u81f4\u3002\u76f8\u5bf9\u5b89\u5168\u7684\u65b9\u6cd5\u662f\u8bbe\u7f6e\u4e00\u4e2a\u6807\u5fd7\u4f4d\uff0c\u8ba9\u7ebf\u7a0b\u5728\u5b8c\u6210\u5f53\u524d\u4efb\u52a1\u540e\u81ea\u884c\u9000\u51fa\u3002\u53ef\u4ee5\u4f7f\u7528<code>threading.Event<\/code>\u5bf9\u8c61\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u901a\u8fc7\u8c03\u7528<code>event.set()<\/code>\u6765\u901a\u77e5\u7ebf\u7a0b\u505c\u6b62\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u6ca1\u6709\u5185\u7f6e\u7684\u65b9\u6cd5\u53ef\u4ee5\u5f3a\u5236\u505c\u6b62\u7ebf\u7a0b\uff1f<\/strong><br \/>Python\u6807\u51c6\u5e93\u5e76\u6ca1\u6709\u63d0\u4f9b\u5f3a\u5236\u505c\u6b62\u7ebf\u7a0b\u7684\u5185\u7f6e\u65b9\u6cd5\u3002\u8bbe\u8ba1\u4e0a\u662f\u4e3a\u4e86\u907f\u514d\u6f5c\u5728\u7684\u98ce\u9669\uff0c\u5982\u6570\u636e\u635f\u574f\u6216\u7a0b\u5e8f\u4e0d\u7a33\u5b9a\u3002\u5efa\u8bae\u4f7f\u7528\u534f\u4f5c\u65b9\u5f0f\uff0c\u8bbe\u8ba1\u7ebf\u7a0b\u5728\u5408\u7406\u7684\u65f6\u95f4\u5185\u68c0\u67e5\u662f\u5426\u9700\u8981\u505c\u6b62\uff0c\u5e76\u505a\u51fa\u76f8\u5e94\u7684\u5904\u7406\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u7ebf\u7a0b\u4e2d\u5904\u7406\u5f02\u5e38\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7a33\u5b9a\uff1f<\/strong><br \/>\u5728\u7ebf\u7a0b\u4e2d\u8fd0\u884c\u7684\u4ee3\u7801\u5e94\u8be5\u4f7f\u7528<code>try...except<\/code>\u7ed3\u6784\u6765\u6355\u83b7\u5f02\u5e38\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u7ebf\u7a0b\u56e0\u672a\u5904\u7406\u7684\u5f02\u5e38\u800c\u5d29\u6e83\u3002\u901a\u8fc7\u5728<code>except<\/code>\u5757\u4e2d\u8fdb\u884c\u5fc5\u8981\u7684\u6e05\u7406\u548c\u65e5\u5fd7\u8bb0\u5f55\uff0c\u53ef\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u6740\u6b7b\u7ebf\u7a0b\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6807\u5fd7\u3001\u4f7f\u7528\u5b88\u62a4\u7ebf\u7a0b\u3001\u4f7f\u7528\u7ebf\u7a0b\u6c60\u3001\u5229\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u63a2\u8ba8 [&hellip;]","protected":false},"author":3,"featured_media":1001524,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001507"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1001507"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001507\/revisions"}],"predecessor-version":[{"id":1001527,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001507\/revisions\/1001527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1001524"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1001507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1001507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1001507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}