{"id":204619,"date":"2025-05-29T08:28:45","date_gmt":"2025-05-29T00:28:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204619\/"},"modified":"2025-05-29T08:28:45","modified_gmt":"2025-05-29T00:28:45","slug":"python-%e5%a4%9a%e7%ba%bf%e7%a8%8b%ef%bc%9a%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e6%af%8f%e5%88%86%e9%92%9f%e6%89%a7%e8%a1%8c%e4%b8%80%e6%ac%a1%e4%bb%bb%e5%8a%a1%ef%bc%8c%e5%90%8c%e6%97%b6%e4%b8%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204619\/","title":{"rendered":"Python \u591a\u7ebf\u7a0b\uff1a\u5982\u4f55\u5b9e\u73b0\u6bcf\u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1\uff0c\u540c\u65f6\u4e0d\u5f71\u54cd\u5176\u4ed6\u4efb\u52a1\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u591a\u7ebf\u7a0b\uff1a\u5982\u4f55\u5b9e\u73b0\u6bcf\u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1\uff0c\u540c\u65f6\u4e0d\u5f71\u54cd\u5176\u4ed6\u4efb\u52a1\uff1f<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241111\/17313260916731f08b576a4.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5728 python \u4e2d\u4f7f\u7528\u591a\u7ebf\u7a0b\u6765\u5b9e\u73b0\u8ba9\u4efb\u52a1\u95f4\u9694 1 \u5206\u949f\u8fd0\u884c\uff0c\u540c\u65f6\u53c8\u4e0d\u5f71\u54cd\u5176\u4ed6\u4efb\u52a1\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u591a\u7ebf\u7a0b\u548c\u65f6\u95f4\u6a21\u5757<\/strong><\/p>\n<pre>import threading\nimport time<\/pre>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u6267\u884c\u95f4\u9694\u4efb\u52a1\u7684\u7ebf\u7a0b<\/strong><\/p>\n<pre>class intervalthread(threading.thread):\n    def run(self):\n        while true:\n            # 5\u5206\u949f\u4e00\u6b21\u6267\u884c\u4efb\u52a1\u7684\u4ee3\u7801\uff08\u5b9e\u9645\u65f6\u95f4\u95f4\u9694\u53ef\u6839\u636e\u60c5\u51b5\u8c03\u6574\uff09\n            time.sleep(300)\n            # \u4efb\u52a1\u4ee3\u7801<\/pre>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u6267\u884c\u5176\u4ed6\u4efb\u52a1\u7684\u7ebf\u7a0b\uff08\u53ef\u9009\uff0c\u5982\u679c\u65e0\u5176\u4ed6\u4efb\u52a1\u53ef\u8df3\u8fc7\u6b64\u6b65\u9aa4\uff09<\/strong><\/p>\n<pre>class nonintervalthread(threading.thread):\n    def run(self):\n        while true:\n            # \u6301\u7eed\u6267\u884c\u7684\u5176\u4ed6\u4efb\u52a1\u7684\u4ee3\u7801<\/pre>\n<\/li>\n<li>\n<p><strong>\u542f\u52a8\u7ebf\u7a0b<\/strong><\/p>\n<pre>interval_thread = IntervalThread()\nnon_interval_thread = NonIntervalThread()\ninterval_thread.start()\nnon_interval_thread.start()<\/pre>\n<\/li>\n<\/ol>\n<p>\u8fd9\u6837\uff0cintervalthread \u7ebf\u7a0b\u5c06\u6bcf 1 \u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1\uff0c\u800c nonintervalthread \u7ebf\u7a0b\u5c06\u6301\u7eed\u6267\u884c\u5176\u4ed6\u4efb\u52a1\u3002\u5176\u4ed6\u4efb\u52a1\u4e0d\u4f1a\u53d7\u5230 intervalthread \u7684\u5f71\u54cd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u591a\u7ebf\u7a0b\uff1a\u5982\u4f55\u5b9e\u73b0\u6bcf&#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-204619","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204619","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=204619"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204619\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}