{"id":172019,"date":"2024-05-08T17:41:39","date_gmt":"2024-05-08T09:41:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/172019.html"},"modified":"2024-05-08T17:41:46","modified_gmt":"2024-05-08T09:41:46","slug":"backtrace-%e5%87%bd%e6%95%b0%e5%9c%a8-python-%e9%a1%b9%e7%9b%ae%e5%bc%80%e5%8f%91%e4%b8%ad%e6%9c%89%e5%93%aa%e4%ba%9b%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/172019.html","title":{"rendered":"backtrace \u51fd\u6570\u5728 python \u9879\u76ee\u5f00\u53d1\u4e2d\u6709\u54ea\u4e9b\u5e94\u7528\u573a\u666f"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27043358\/8c536a4d-0a2b-44ed-9b2c-4846131f84e7.webp\" alt=\"backtrace \u51fd\u6570\u5728 python \u9879\u76ee\u5f00\u53d1\u4e2d\u6709\u54ea\u4e9b\u5e94\u7528\u573a\u666f\" \/><\/p>\n<p><p>\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c<strong>backtrace\u51fd\u6570<\/strong>\u4e3b\u8981\u5e94\u7528\u4e8e<strong>\u8c03\u8bd5\u3001\u9519\u8bef\u5904\u7406\u3001\u6027\u80fd\u5206\u6790<\/strong>\u7b49\u573a\u666f\u3002\u5176\u4e2d\uff0c<strong>\u9519\u8bef\u5904\u7406\u662f\u5c24\u4e3a\u91cd\u8981\u7684\u4e00\u4e2a\u5e94\u7528\u65b9\u9762<\/strong>\u3002\u8fd9\u80fd\u5e2e\u52a9\u5f00\u53d1\u8005\u5728\u7a0b\u5e8f\u5d29\u6e83\u6216\u5f02\u5e38\u9000\u51fa\u65f6\uff0c\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u6e90\u5934\u3002\u901a\u8fc7\u6355\u83b7\u7a0b\u5e8f\u5d29\u6e83\u7684\u65f6\u523b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u83b7\u5f97\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u6808\u7684\u5feb\u7167\uff0c\u8be5\u5feb\u7167\u8be6\u7ec6\u8bb0\u5f55\u4e86\u7a0b\u5e8f\u8fd0\u884c\u72b6\u6001\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u51fd\u6570\u8c03\u7528\u987a\u5e8f\u3001\u53d8\u91cf\u72b6\u6001\u7b49\uff0c\u4ece\u800c\u4f7f\u5f97\u95ee\u9898\u7684\u8c03\u8bd5\u53d8\u5f97\u66f4\u4e3a\u76f4\u89c2\u548c\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>\u9519\u8bef\u5904\u7406\u4e2d\u7684\u5177\u4f53\u5e94\u7528\u5305\u62ec\u4f7f\u7528\u6807\u51c6\u5e93\u4e2d\u7684<code>traceback<\/code>\u6a21\u5757\u8f93\u51fa\u9519\u8bef\u5806\u6808\u4fe1\u606f\u3002\u5f53\u7a0b\u5e8f\u9047\u5230\u5f02\u5e38\u65f6\uff0c<code>traceback<\/code>\u6a21\u5757\u53ef\u4ee5\u88ab\u7528\u6765\u6355\u6349\u8fd9\u4e2a\u5f02\u5e38\uff0c\u5e76\u6253\u5370\u51fa\u9519\u8bef\u7684\u5b8c\u6574\u5806\u6808\u4fe1\u606f\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u8ffd\u8e2a\u5230\u95ee\u9898\u53d1\u751f\u7684\u5177\u4f53\u4f4d\u7f6e\u3002\u6b64\u5916\uff0c\u5f00\u53d1\u8005\u8fd8\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49<code>traceback<\/code>\u7684\u5c55\u793a\u65b9\u5f0f\u6765\u66f4\u597d\u5730\u9002\u5e94\u4e0d\u540c\u7684\u8c03\u8bd5\u573a\u666f\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001 \u8c03\u8bd5<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4ee3\u7801\u7684\u8c03\u8bd5\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u73af\u3002\u4f7f\u7528backtrace\u51fd\u6570\u80fd\u591f\u5728\u7a0b\u5e8f\u51fa\u73b0\u9519\u8bef\u65f6\uff0c\u7acb\u5373\u5c55\u73b0\u51fa\u7a0b\u5e8f\u7684\u8c03\u7528\u8f68\u8ff9\u3002<strong>\u8fd9\u5bf9\u4e8e\u67e5\u627e\u548c\u89e3\u51b3\u7f16\u7801\u9519\u8bef\u5c24\u4e3a\u5173\u952e<\/strong>\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u67e5\u627e\u9519\u8bef\u6765\u6e90<\/strong>\uff1a\u901a\u8fc7\u5206\u6790backtrace\u63d0\u4f9b\u7684\u51fd\u6570\u8c03\u7528\u6808\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8fc5\u901f\u5b9a\u4f4d\u5230\u5f15\u53d1\u9519\u8bef\u7684\u5177\u4f53\u4ee3\u7801\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u7701\u53bb\u4e86\u9010\u6b65\u67e5\u9a8c\u4ee3\u7801\u7684\u9ebb\u70e6\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u590d\u6742\u9879\u76ee\u65f6\uff0c\u6548\u7387\u63d0\u5347\u660e\u663e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7406\u89e3\u7a0b\u5e8f\u6d41\u7a0b<\/strong>\uff1a\u5728\u9879\u76ee\u7684\u65e9\u671f\u9636\u6bb5\uff0c\u7406\u89e3\u4ee3\u7801\u7684\u6267\u884c\u6d41\u7a0b\u5c24\u4e3a\u91cd\u8981\u3002\u901a\u8fc7\u89c2\u5bdf\u51fd\u6570\u7684\u8c03\u7528\u987a\u5e8f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u628a\u63e1\u4ee3\u7801\u7684\u8fd0\u884c\u903b\u8f91\uff0c\u6709\u52a9\u4e8e\u540e\u7eed\u7684\u4ee3\u7801\u7f16\u5199\u548c\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h2>\u4e8c\u3001 \u9519\u8bef\u5904\u7406<\/h2>\n<\/p>\n<p><p>\u9519\u8bef\u5904\u7406\u662fbacktrace\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u573a\u666f\u4e4b\u4e00\u3002\u6b63\u786e\u7684\u9519\u8bef\u5904\u7406\u4e0d\u4ec5\u80fd\u63d0\u5347\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\uff0c\u8fd8\u80fd\u589e\u5f3a\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5feb\u901f\u5b9a\u4f4d\u548c\u4fee\u590d\u9519\u8bef<\/strong>\uff1a\u5f53\u7a0b\u5e8f\u51fa\u73b0\u672a\u9884\u671f\u7684\u9519\u8bef\u65f6\uff0c\u7acb\u5373\u6355\u83b7\u5e76\u8bb0\u5f55\u4e0b\u9519\u8bef\u53d1\u751f\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\u5bf9\u4e8e\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u81f3\u5173\u91cd\u8981\u3002<strong>backtrace\u53ef\u4ee5\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u8fd9\u4e00\u4fe1\u606f\uff0c\u5e2e\u52a9\u4ed6\u4eec\u66f4\u5feb\u5730\u89e3\u51b3\u95ee\u9898<\/strong>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55<\/strong>\uff1a\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u901a\u8fc7backtrace\u51fd\u6570\u8bb0\u5f55\u8be6\u7ec6\u7684\u9519\u8bef\u65e5\u5fd7\u662f\u4e00\u79cd\u5e38\u89c1\u505a\u6cd5\u3002\u8fd9\u4e0d\u4ec5\u53ef\u4ee5\u5e2e\u52a9\u7ef4\u62a4\u56e2\u961f\u5728\u53d1\u751f\u95ee\u9898\u65f6\u5feb\u901f\u54cd\u5e94\uff0c\u8fd8\u53ef\u4ee5\u7528\u4e8e\u540e\u7eed\u7684\u9519\u8bef\u5206\u6790\u548c\u7cfb\u7edf\u4f18\u5316\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h2>\u4e09\u3001 \u6027\u80fd\u5206\u6790<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u8c03\u8bd5\u548c\u9519\u8bef\u5904\u7406\u4e4b\u5916\uff0cbacktrace\u4e5f\u5e38\u7528\u4e8e\u6027\u80fd\u5206\u6790\u3002\u901a\u8fc7\u8bc4\u4f30\u51fd\u6570\u8c03\u7528\u7684\u9891\u7387\u548c\u8017\u65f6\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8bc6\u522b\u51fa\u7a0b\u5e8f\u7684\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u6027\u80fd\u74f6\u9888\u8bc6\u522b<\/strong>\uff1a\u901a\u8fc7\u5bf9backtrace\u65e5\u5fd7\u7684\u5206\u6790\uff0c\u53ef\u4ee5\u8f7b\u677e\u53d1\u73b0\u7a0b\u5e8f\u4e2d\u7684\u6027\u80fd\u74f6\u9888\u3002<strong>\u8fd9\u5305\u62ec\u4e86\u9891\u7e41\u8c03\u7528\u7684\u51fd\u6570\u3001\u6267\u884c\u65f6\u95f4\u957f\u7684\u4ee3\u7801\u6bb5\u7b49<\/strong>\uff0c\u4e3a\u6027\u80fd\u4f18\u5316\u63d0\u4f9b\u4e86\u4f9d\u636e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6027\u80fd\u5bf9\u6bd4\u5206\u6790<\/strong>\uff1a\u5728\u8fdb\u884c\u4ee3\u7801\u4f18\u5316\u540e\uff0c\u901a\u8fc7\u6bd4\u8f83\u4f18\u5316\u524d\u540e\u7684backtrace\u65e5\u5fd7\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u76f4\u89c2\u5730\u770b\u5230\u4f18\u5316\u7684\u6548\u679c\uff0c\u5305\u62ec\u6027\u80fd\u63d0\u5347\u7684\u8303\u56f4\u548c\u76f8\u5173\u7684\u6027\u80fd\u6307\u6807\u53d8\u5316\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><h2>\u56db\u3001 \u5176\u4ed6\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><p>backtrace\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\u8fd8\u6709\u4e00\u4e9b\u7279\u6b8a\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<ul>\n<li>\n<p><strong>\u5e76\u53d1\u548c\u5f02\u6b65\u7f16\u7a0b<\/strong>\uff1a\u5728\u5904\u7406\u5e76\u53d1\u548c\u5f02\u6b65\u7f16\u7a0b\u65f6\uff0c\u51c6\u786e\u5730\u7406\u89e3\u7a0b\u5e8f\u7684\u72b6\u6001\u975e\u5e38\u5173\u952e\u3002backtrace\u80fd\u63d0\u4f9b\u4e00\u79cd\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u5e76\u53d1\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u548c\u72b6\u6001\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u5ba1\u8ba1<\/strong>\uff1a\u901a\u8fc7\u5206\u6790backtrace\u65e5\u5fd7\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5b89\u5168\u4e13\u5bb6\u8bc6\u522b\u6f5c\u5728\u7684\u5b89\u5168\u6f0f\u6d1e\uff0c\u6bd4\u5982\u9519\u8bef\u7684\u5f02\u5e38\u5904\u7406\u6d41\u7a0b\u3001\u4e0d\u5b89\u5168\u7684\u51fd\u6570\u8c03\u7528\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<\/ul>\n<p><p>\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u6709\u6548\u5229\u7528backtrace\u51fd\u6570\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u8fd8\u53ef\u4ee5\u589e\u5f3a\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u548c\u6027\u80fd\u3002\u901a\u8fc7\u4e0d\u65ad\u5730\u5b9e\u8df5\u548c\u603b\u7ed3\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u52a0\u719f\u7ec3\u5730\u8fd0\u7528\u8fd9\u4e00\u5de5\u5177\uff0c\u4e3a\u9879\u76ee\u5f00\u53d1\u6dfb\u7816\u52a0\u74e6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. backtrace\u51fd\u6570\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\u573a\u666f\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>backtrace\u51fd\u6570\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\u53ef\u4ee5\u7528\u4e8e\u6355\u83b7\u548c\u8c03\u8bd5\u5f02\u5e38\u3002\u5f53\u7a0b\u5e8f\u51fa\u73b0\u9519\u8bef\u6216\u5f02\u5e38\u65f6\uff0cbacktrace\u51fd\u6570\u80fd\u591f\u63d0\u4f9b\u9519\u8bef\u53d1\u751f\u7684\u4f4d\u7f6e\u548c\u8c03\u7528\u5806\u6808\u4fe1\u606f\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u8ffd\u8e2a\u548c\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u4f7f\u7528backtrace\u51fd\u6570\u6765\u8c03\u8bd5Python\u9879\u76ee\uff1f<\/strong><\/p>\n<p>\u8981\u4f7f\u7528backtrace\u51fd\u6570\u8c03\u8bd5Python\u9879\u76ee\uff0c\u53ef\u4ee5\u4f7f\u7528try-except\u5757\u6765\u6355\u83b7\u5f02\u5e38\uff0c\u5728\u5f02\u5e38\u53d1\u751f\u65f6\u8c03\u7528backtrace\u51fd\u6570\u6253\u5370\u9519\u8bef\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u4ee3\u7801\u4e2d\u63d2\u5165backtrace\u51fd\u6570\u6765\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u8c03\u7528\u5806\u6808\u4fe1\u606f\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u5206\u6790\u95ee\u9898\u6240\u5728\u3002<\/p>\n<p><strong>3. backtrace\u51fd\u6570\u8fd8\u6709\u5176\u4ed6\u7684\u7528\u9014\u5417\uff1f<\/strong><\/p>\n<p>\u9664\u4e86\u7528\u4e8e\u8c03\u8bd5\u5f02\u5e38\uff0cbacktrace\u51fd\u6570\u8fd8\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u4e00\u4e9b\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u6027\u80fd\u5206\u6790\u548c\u4ee3\u7801\u8986\u76d6\u7387\u6d4b\u8bd5\u3002\u901a\u8fc7\u5728\u5173\u952e\u4f4d\u7f6e\u63d2\u5165backtrace\u51fd\u6570\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u968f\u65f6\u83b7\u53d6\u8c03\u7528\u5806\u6808\u4fe1\u606f\uff0c\u4ece\u800c\u8fdb\u884c\u6027\u80fd\u5206\u6790\u548c\u4f18\u5316\u3002\u540c\u65f6\uff0c\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u5de5\u5177\u548c\u6280\u672f\u6765\u5b9e\u73b0\u4ee3\u7801\u8986\u76d6\u7387\u6d4b\u8bd5\uff0c\u4f8b\u5982\u5c06backtrace\u51fd\u6570\u4e0e\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u4fbf\u66f4\u5168\u9762\u5730\u6d4b\u8bd5\u4ee3\u7801\u8986\u76d6\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u9879\u76ee\u5f00\u53d1\u4e2d\uff0cbacktrace\u51fd\u6570\u4e3b\u8981\u5e94\u7528\u4e8e\u8c03\u8bd5\u3001\u9519\u8bef\u5904\u7406\u3001\u6027\u80fd\u5206\u6790\u7b49\u573a\u666f\u3002\u5176\u4e2d\uff0c\u9519\u8bef\u5904\u7406\u662f\u5c24\u4e3a [&hellip;]","protected":false},"author":3,"featured_media":172028,"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\/172019"}],"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=172019"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/172019\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/172028"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=172019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=172019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=172019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}