{"id":509,"date":"2019-08-17T09:53:55","date_gmt":"2019-08-17T01:53:55","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=509"},"modified":"2019-10-15T16:17:34","modified_gmt":"2019-10-15T08:17:34","slug":"2tsd","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/","title":{"rendered":"2.0 \u8c03\u8bd5 Debugging"},"content":{"rendered":"\n

\u8c03\u8bd5\uff08Debugging\uff09<\/h1>\n\n\n\n

\u5229\u7528\u597d\u8c03\u8bd5\uff0c\u80fd\u5927\u5927\u63d0\u9ad8\u4f60\u6355\u6349\u4ee3\u7801Bug\u7684\u3002\u5927\u90e8\u5206\u65b0\u4eba\u5ffd\u7565\u4e86Python debugger(pdb<\/code>)\u7684\u91cd\u8981\u6027\u3002 \u5728\u8fd9\u4e2a\u7ae0\u8282\u6211\u53ea\u4f1a\u544a\u8bc9\u4f60\u4e00\u4e9b\u91cd\u8981\u7684\u547d\u4ee4\uff0c\u4f60\u53ef\u4ee5\u4ece\u5b98\u65b9\u6587\u6863\u4e2d\u5b66\u4e60\u5230\u66f4\u591a\u3002<\/p>\n\n\n\n

\u8bd1\u8005\u6ce8\uff0c\u53c2\u8003\uff1ahttps:\/\/docs.python.org\/2\/library\/pdb.html Or https:\/\/docs.python.org\/3\/library\/pdb.html<\/p>

\u539f\u6587; https:\/\/docs.pythontab.com\/interpy\/Debugging\/README\/<\/a> <\/p><\/blockquote>\n\n\n\n

\u4ece\u547d\u4ee4\u884c\u8fd0\u884c<\/h3>\n\n\n\n

\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4f7f\u7528Python debugger\u8fd0\u884c\u4e00\u4e2a\u811a\u672c\uff0c \u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n

$ python -m pdb my_script.py\n<\/code><\/pre>\n\n\n\n

\u8fd9\u4f1a\u89e6\u53d1debugger\u5728\u811a\u672c\u7b2c\u4e00\u884c\u6307\u4ee4\u5904\u505c\u6b62\u6267\u884c\u3002\u8fd9\u5728\u811a\u672c\u5f88\u77ed\u65f6\u4f1a\u5f88\u6709\u5e2e\u52a9\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7(Pdb)\u6a21\u5f0f\u63a5\u7740\u67e5\u770b\u53d8\u91cf\u4fe1\u606f\uff0c\u5e76\u4e14\u9010\u884c\u8c03\u8bd5\u3002<\/p>\n\n\n\n

\u4ece\u811a\u672c\u5185\u90e8\u8fd0\u884c<\/h3>\n\n\n\n

\u540c\u65f6\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728\u811a\u672c\u5185\u90e8\u8bbe\u7f6e\u65ad\u70b9\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u67d0\u4e9b\u7279\u5b9a\u70b9\u67e5\u770b\u53d8\u91cf\u4fe1\u606f\u548c\u5404\u79cd\u6267\u884c\u65f6\u4fe1\u606f\u4e86\u3002\u8fd9\u91cc\u5c06\u4f7f\u7528pdb.set_trace()<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n

import pdb\n\ndef make_bread():\n    pdb.set_trace()\n    return \"I don't have time\"\n\nprint(make_bread())\n<\/code><\/pre>\n\n\n\n

\u8bd5\u4e0b\u4fdd\u5b58\u4e0a\u9762\u7684\u811a\u672c\u540e\u8fd0\u884c\u4e4b\u3002\u4f60\u4f1a\u5728\u8fd0\u884c\u65f6\u9a6c\u4e0a\u8fdb\u5165debugger\u6a21\u5f0f\u3002\u73b0\u5728\u662f\u65f6\u5019\u4e86\u89e3\u4e0bdebugger\u6a21\u5f0f\u4e0b\u7684\u4e00\u4e9b\u547d\u4ee4\u4e86\u3002<\/p>\n\n\n\n

\u547d\u4ee4\u5217\u8868\uff1a<\/h5>\n\n\n\n
  • c<\/code>: \u7ee7\u7eed\u6267\u884c<\/li>
  • w<\/code>: \u663e\u793a\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\u884c\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f<\/li>
  • a<\/code>: \u6253\u5370\u5f53\u524d\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868<\/li>
  • s<\/code>: \u6267\u884c\u5f53\u524d\u4ee3\u7801\u884c\uff0c\u5e76\u505c\u5728\u7b2c\u4e00\u4e2a\u80fd\u505c\u7684\u5730\u65b9\uff08\u76f8\u5f53\u4e8e\u5355\u6b65\u8fdb\u5165\uff09<\/li>
  • n<\/code>: \u7ee7\u7eed\u6267\u884c\u5230\u5f53\u524d\u51fd\u6570\u7684\u4e0b\u4e00\u884c\uff0c\u6216\u8005\u5f53\u524d\u884c\u76f4\u63a5\u8fd4\u56de\uff08\u5355\u6b65\u8df3\u8fc7\uff09<\/li><\/ul>\n\n\n\n

    \u5355\u6b65\u8df3\u8fc7\uff08n<\/code>ext\uff09\u548c\u5355\u6b65\u8fdb\u5165\uff08s<\/code>tep\uff09\u7684\u533a\u522b\u5728\u4e8e\uff0c \u5355\u6b65\u8fdb\u5165\u4f1a\u8fdb\u5165\u5f53\u524d\u884c\u8c03\u7528\u7684\u51fd\u6570\u5185\u90e8\u5e76\u505c\u5728\u91cc\u9762\uff0c \u800c\u5355\u6b65\u8df3\u8fc7\u4f1a\uff08\u51e0\u4e4e\uff09\u5168\u901f\u6267\u884c\u5b8c\u5f53\u524d\u884c\u8c03\u7528\u7684\u51fd\u6570\uff0c\u5e76\u505c\u5728\u5f53\u524d\u51fd\u6570\u7684\u4e0b\u4e00\u884c\u3002<\/p>\n\n\n\n

    pdb\u771f\u7684\u662f\u4e00\u4e2a\u5f88\u65b9\u4fbf\u7684\u529f\u80fd\uff0c\u4e0a\u9762\u4ec5\u5217\u4e3e\u5c11\u91cf\u7528\u6cd5\uff0c\u66f4\u591a\u7684\u547d\u4ee4\u5f3a\u70c8\u63a8\u8350\u4f60\u53bb\u770b\u5b98\u65b9\u6587\u6863\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u8c03\u8bd5\uff08Debugging\uff09 \u5229\u7528\u597d\u8c03\u8bd5\uff0c\u80fd\u5927\u5927\u63d0\u9ad8\u4f60\u6355\u6349\u4ee3\u7801Bug\u7684\u3002\u5927\u90e8\u5206\u65b0\u4eba\u5ffd\u7565\u4e86Python debug<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,13],"tags":[],"yoast_head":"\n2.0 \u8c03\u8bd5 Debugging - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"2.0 \u8c03\u8bd5 Debugging - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\" \/>\n<meta property=\"og:description\" content=\"\u8c03\u8bd5\uff08Debugging\uff09 \u5229\u7528\u597d\u8c03\u8bd5\uff0c\u80fd\u5927\u5927\u63d0\u9ad8\u4f60\u6355\u6349\u4ee3\u7801Bug\u7684\u3002\u5927\u90e8\u5206\u65b0\u4eba\u5ffd\u7565\u4e86Python debug\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-17T01:53:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-15T08:17:34+00:00\" \/>\n<meta name=\"author\" content=\"\u7ba1\u7406\u5458\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\"},\"author\":{\"name\":\"\u7ba1\u7406\u5458\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"headline\":\"2.0 \u8c03\u8bd5 Debugging\",\"datePublished\":\"2019-08-17T01:53:55+00:00\",\"dateModified\":\"2019-10-15T08:17:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\"},\"wordCount\":36,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"articleSection\":[\"Linux\",\"Python\"],\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\",\"url\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\",\"name\":\"2.0 \u8c03\u8bd5 Debugging - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#website\"},\"datePublished\":\"2019-08-17T01:53:55+00:00\",\"dateModified\":\"2019-10-15T08:17:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#breadcrumb\"},\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.linuxdevops.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\/\/www.linuxdevops.cn\/linux\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"2.0 \u8c03\u8bd5 Debugging\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#website\",\"url\":\"https:\/\/www.linuxdevops.cn\/\",\"name\":\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\",\"description\":\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\u7b14\u8bb0\",\"publisher\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"alternateName\":\"linuxdevops\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.linuxdevops.cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-CN\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\",\"name\":\"\u7ba1\u7406\u5458\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-CN\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg\",\"contentUrl\":\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg\",\"width\":512,\"height\":512,\"caption\":\"\u7ba1\u7406\u5458\"},\"logo\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/\"},\"description\":\"\u7ba1\u7406\u5458\",\"url\":\"https:\/\/www.linuxdevops.cn\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"2.0 \u8c03\u8bd5 Debugging - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/","og_locale":"zh_CN","og_type":"article","og_title":"2.0 \u8c03\u8bd5 Debugging - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","og_description":"\u8c03\u8bd5\uff08Debugging\uff09 \u5229\u7528\u597d\u8c03\u8bd5\uff0c\u80fd\u5927\u5927\u63d0\u9ad8\u4f60\u6355\u6349\u4ee3\u7801Bug\u7684\u3002\u5927\u90e8\u5206\u65b0\u4eba\u5ffd\u7565\u4e86Python debug","og_url":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/","og_site_name":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","article_published_time":"2019-08-17T01:53:55+00:00","article_modified_time":"2019-10-15T08:17:34+00:00","author":"\u7ba1\u7406\u5458","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#article","isPartOf":{"@id":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/"},"author":{"name":"\u7ba1\u7406\u5458","@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"headline":"2.0 \u8c03\u8bd5 Debugging","datePublished":"2019-08-17T01:53:55+00:00","dateModified":"2019-10-15T08:17:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/"},"wordCount":36,"commentCount":0,"publisher":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"articleSection":["Linux","Python"],"inLanguage":"zh-CN","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/","url":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/","name":"2.0 \u8c03\u8bd5 Debugging - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","isPartOf":{"@id":"https:\/\/www.linuxdevops.cn\/#website"},"datePublished":"2019-08-17T01:53:55+00:00","dateModified":"2019-10-15T08:17:34+00:00","breadcrumb":{"@id":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#breadcrumb"},"inLanguage":"zh-CN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.linuxdevops.cn\/2019\/08\/2tsd\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.linuxdevops.cn\/"},{"@type":"ListItem","position":2,"name":"Linux","item":"https:\/\/www.linuxdevops.cn\/linux\/"},{"@type":"ListItem","position":3,"name":"2.0 \u8c03\u8bd5 Debugging"}]},{"@type":"WebSite","@id":"https:\/\/www.linuxdevops.cn\/#website","url":"https:\/\/www.linuxdevops.cn\/","name":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","description":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\u7b14\u8bb0","publisher":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"alternateName":"linuxdevops","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.linuxdevops.cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-CN"},{"@type":["Person","Organization"],"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1","name":"\u7ba1\u7406\u5458","image":{"@type":"ImageObject","inLanguage":"zh-CN","@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/","url":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg","contentUrl":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg","width":512,"height":512,"caption":"\u7ba1\u7406\u5458"},"logo":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/"},"description":"\u7ba1\u7406\u5458","url":"https:\/\/www.linuxdevops.cn\/author\/root\/"}]}},"_links":{"self":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/509"}],"collection":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/comments?post=509"}],"version-history":[{"count":1,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/509\/revisions"}],"predecessor-version":[{"id":510,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/509\/revisions\/510"}],"wp:attachment":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/media?parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/categories?post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/tags?post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}