{"id":991857,"date":"2024-12-27T08:32:31","date_gmt":"2024-12-27T00:32:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/991857.html"},"modified":"2024-12-27T08:32:33","modified_gmt":"2024-12-27T00:32:33","slug":"python%e5%a6%82%e4%bd%95%e8%af%bb%e5%8f%96cpu%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/991857.html","title":{"rendered":"python\u5982\u4f55\u8bfb\u53d6cpu\u4fe1\u606f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065942\/b511b08f-8f51-4f7b-ab0f-dd7da61b0736.webp\" alt=\"python\u5982\u4f55\u8bfb\u53d6cpu\u4fe1\u606f\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/>\u5728Python\u4e2d\uff0c\u8bfb\u53d6CPU\u4fe1\u606f\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<strong><code>psutil<\/code>\u5e93\u3001<code>platform<\/code>\u6a21\u5757\u3001<code>os<\/code>\u6a21\u5757<\/strong>\u7b49\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u5176\u4e2d\uff0c<code>psutil<\/code>\u5e93\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u5e93\uff0c\u80fd\u591f\u63d0\u4f9b\u7cfb\u7edf\u548c\u8fdb\u7a0b\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u975e\u5e38\u9002\u5408\u7528\u4e8e\u83b7\u53d6CPU\u7684\u8be6\u7ec6\u6570\u636e\u3002\u4f7f\u7528<code>psutil<\/code>\u5e93\u53ef\u4ee5\u83b7\u53d6CPU\u7684\u6838\u5fc3\u6570\u91cf\u3001\u4f7f\u7528\u7387\u3001\u9891\u7387\u7b49\u4fe1\u606f\u3002\u8fd9\u4e9b\u4fe1\u606f\u5bf9\u4e8e\u6027\u80fd\u76d1\u63a7\u548c\u7cfb\u7edf\u5206\u6790\u975e\u5e38\u6709\u7528\u3002\u901a\u8fc7<code>platform<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u83b7\u53d6\u5230\u7cfb\u7edf\u7c7b\u578b\u3001\u7248\u672c\u7b49\u57fa\u7840\u4fe1\u606f\u3002<code>os<\/code>\u6a21\u5757\u5219\u53ef\u4ee5\u7528\u4e8e\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\uff0c\u4ece\u800c\u83b7\u53d6\u66f4\u52a0\u5e95\u5c42\u7684CPU\u4fe1\u606f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u8bfb\u53d6CPU\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528PSUTIL\u5e93\u8bfb\u53d6CPU\u4fe1\u606f  <\/p>\n<\/p>\n<p><p><code>psutil<\/code>\u5e93\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6\u7cfb\u7edf\u7684\u5404\u79cd\u4fe1\u606f\uff0c\u5305\u62ecCPU\u3001\u5185\u5b58\u3001\u78c1\u76d8\u3001\u7f51\u7edc\u7b49\u3002\u5b83\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u5e93\uff0c\u652f\u6301Windows\u3001Linux\u3001macOS\u7b49\u64cd\u4f5c\u7cfb\u7edf\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u5bfc\u5165PSUTIL\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528<code>psutil<\/code>\u5e93\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install psutil<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u8be5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import psutil<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u83b7\u53d6CPU\u6838\u5fc3\u6570\u91cf<\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>psutil.cpu_count()<\/code>\u65b9\u6cd5\u6765\u83b7\u53d6CPU\u7684\u6838\u5fc3\u6570\u91cf\u3002\u8be5\u65b9\u6cd5\u6709\u4e00\u4e2a\u53ef\u9009\u53c2\u6570<code>logical<\/code>\uff0c\u5f53\u8bbe\u7f6e\u4e3a<code>True<\/code>\u65f6\uff0c\u8fd4\u56de\u903b\u8f91\u6838\u5fc3\u6570\uff1b\u8bbe\u7f6e\u4e3a<code>False<\/code>\u65f6\uff0c\u8fd4\u56de\u7269\u7406\u6838\u5fc3\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u903b\u8f91\u6838\u5fc3\u6570<\/p>\n<p>logical_cores = psutil.cpu_count(logical=True)<\/p>\n<p>print(f&quot;Logical cores: {logical_cores}&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u7269\u7406\u6838\u5fc3\u6570<\/strong><\/h2>\n<p>physical_cores = psutil.cpu_count(logical=False)<\/p>\n<p>print(f&quot;Physical cores: {physical_cores}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u83b7\u53d6CPU\u4f7f\u7528\u7387<\/li>\n<\/ol>\n<p><p><code>psutil<\/code>\u63d0\u4f9b\u4e86\u83b7\u53d6CPU\u4f7f\u7528\u7387\u7684\u51fd\u6570<code>psutil.cpu_percent(interval=1, percpu=True)<\/code>\u3002\u5176\u4e2d\uff0c<code>interval<\/code>\u53c2\u6570\u8868\u793a\u8ba1\u7b97CPU\u4f7f\u7528\u7387\u7684\u65f6\u95f4\u95f4\u9694\uff0c<code>percpu<\/code>\u53c2\u6570\u4e3a<code>True<\/code>\u65f6\uff0c\u4f1a\u8fd4\u56de\u6bcf\u4e2a\u6838\u5fc3\u7684\u4f7f\u7528\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u6bcf\u4e2a\u6838\u5fc3\u7684CPU\u4f7f\u7528\u7387<\/p>\n<p>cpu_percent_per_core = psutil.cpu_percent(interval=1, percpu=True)<\/p>\n<p>print(f&quot;CPU percent per core: {cpu_percent_per_core}&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u6574\u4f53CPU\u4f7f\u7528\u7387<\/strong><\/h2>\n<p>cpu_percent_total = psutil.cpu_percent(interval=1, percpu=False)<\/p>\n<p>print(f&quot;Total CPU percent: {cpu_percent_total}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u83b7\u53d6CPU\u9891\u7387<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>psutil.cpu_freq()<\/code>\u65b9\u6cd5\u83b7\u53d6CPU\u7684\u5f53\u524d\u9891\u7387\u3001\u6700\u5c0f\u9891\u7387\u548c\u6700\u5927\u9891\u7387\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6CPU\u9891\u7387<\/p>\n<p>cpu_freq = psutil.cpu_freq()<\/p>\n<p>print(f&quot;CPU frequency: {cpu_freq.current} MHz (Min: {cpu_freq.min} MHz, Max: {cpu_freq.max} MHz)&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528PLATFORM\u6a21\u5757\u83b7\u53d6\u7cfb\u7edf\u4fe1\u606f  <\/p>\n<\/p>\n<p><p>\u867d\u7136<code>platform<\/code>\u6a21\u5757\u4e0d\u80fd\u76f4\u63a5\u63d0\u4f9b\u8be6\u7ec6\u7684CPU\u4fe1\u606f\uff0c\u4f46\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u7684\u57fa\u7840\u4fe1\u606f\uff0c\u8fd9\u5bf9\u4e8e\u4e86\u89e3\u7cfb\u7edf\u73af\u5883\u662f\u6709\u5e2e\u52a9\u7684\u3002<\/p>\n<\/p>\n<ol>\n<li>\u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u540d\u79f0\u548c\u7248\u672c<\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>platform.system()<\/code>\u548c<code>platform.version()<\/code>\u6765\u83b7\u53d6\u7cfb\u7edf\u540d\u79f0\u548c\u7248\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import platform<\/p>\n<h2><strong>\u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u540d\u79f0<\/strong><\/h2>\n<p>os_name = platform.system()<\/p>\n<p>print(f&quot;Operating System: {os_name}&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c<\/strong><\/h2>\n<p>os_version = platform.version()<\/p>\n<p>print(f&quot;OS Version: {os_version}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u83b7\u53d6\u5904\u7406\u5668\u4fe1\u606f<\/li>\n<\/ol>\n<p><p><code>platform.processor()<\/code>\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u5904\u7406\u5668\u7684\u4fe1\u606f\uff0c\u4e0d\u8fc7\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u8fd4\u56de\u7684\u7ed3\u679c\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u5904\u7406\u5668\u4fe1\u606f<\/p>\n<p>processor_info = platform.processor()<\/p>\n<p>print(f&quot;Processor: {processor_info}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528OS\u6a21\u5757\u6267\u884c\u7cfb\u7edf\u547d\u4ee4  <\/p>\n<\/p>\n<p><p><code>os<\/code>\u6a21\u5757\u5141\u8bb8\u6211\u4eec\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\uff0c\u8fd9\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u66f4\u5e95\u5c42\u7684CPU\u4fe1\u606f\uff0c\u5c24\u5176\u662f\u5728Linux\u7cfb\u7edf\u4e2d\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6267\u884c\u7cfb\u7edf\u547d\u4ee4<\/li>\n<\/ol>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>os.popen()<\/code>\u6765\u6267\u884c\u547d\u4ee4\u5e76\u8bfb\u53d6\u8f93\u51fa\u3002\u4f8b\u5982\uff0c\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>lscpu<\/code>\u547d\u4ee4\u83b7\u53d6CPU\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u6267\u884clscpu\u547d\u4ee4\u5e76\u8bfb\u53d6\u8f93\u51fa<\/strong><\/h2>\n<p>cpu_info = os.popen(&quot;lscpu&quot;).read()<\/p>\n<p>print(cpu_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528\u5b50\u8fdb\u7a0b\u6a21\u5757<\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u547d\u4ee4\u6216\u9700\u8981\u5904\u7406\u8f93\u51fa\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u3002\u5b83\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u529f\u80fd\u6765\u7ba1\u7406\u5b50\u8fdb\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import subprocess<\/p>\n<h2><strong>\u4f7f\u7528subprocess\u6267\u884c\u547d\u4ee4<\/strong><\/h2>\n<p>result = subprocess.run([&quot;lscpu&quot;], capture_output=True, text=True)<\/p>\n<p>print(result.stdout)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u83b7\u53d6\u8be6\u7ec6CPU\u4fe1\u606f  <\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u7ed3\u5408\u4f7f\u7528<code>psutil<\/code>\u5e93\u3001<code>platform<\/code>\u6a21\u5757\u548c<code>os<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u83b7\u53d6\u5230\u66f4\u52a0\u5168\u9762\u7684CPU\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ol>\n<li>\u7efc\u5408\u793a\u4f8b<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7efc\u5408\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u83b7\u53d6CPU\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import psutil<\/p>\n<p>import platform<\/p>\n<p>import os<\/p>\n<p>import subprocess<\/p>\n<h2><strong>\u4f7f\u7528psutil\u83b7\u53d6CPU\u4fe1\u606f<\/strong><\/h2>\n<p>logical_cores = psutil.cpu_count(logical=True)<\/p>\n<p>physical_cores = psutil.cpu_count(logical=False)<\/p>\n<p>cpu_percent_total = psutil.cpu_percent(interval=1, percpu=False)<\/p>\n<p>cpu_freq = psutil.cpu_freq()<\/p>\n<h2><strong>\u4f7f\u7528platform\u83b7\u53d6\u7cfb\u7edf\u4fe1\u606f<\/strong><\/h2>\n<p>os_name = platform.system()<\/p>\n<p>os_version = platform.version()<\/p>\n<p>processor_info = platform.processor()<\/p>\n<h2><strong>\u4f7f\u7528os\u6267\u884c\u547d\u4ee4\u83b7\u53d6CPU\u4fe1\u606f<\/strong><\/h2>\n<p>cpu_info_os = os.popen(&quot;lscpu&quot;).read()<\/p>\n<h2><strong>\u4f7f\u7528subprocess\u83b7\u53d6CPU\u4fe1\u606f<\/strong><\/h2>\n<p>result = subprocess.run([&quot;lscpu&quot;], capture_output=True, text=True)<\/p>\n<h2><strong>\u8f93\u51fa\u7efc\u5408\u4fe1\u606f<\/strong><\/h2>\n<p>print(f&quot;Logical cores: {logical_cores}&quot;)<\/p>\n<p>print(f&quot;Physical cores: {physical_cores}&quot;)<\/p>\n<p>print(f&quot;Total CPU percent: {cpu_percent_total}&quot;)<\/p>\n<p>print(f&quot;CPU frequency: {cpu_freq.current} MHz (Min: {cpu_freq.min} MHz, Max: {cpu_freq.max} MHz)&quot;)<\/p>\n<p>print(f&quot;Operating System: {os_name}&quot;)<\/p>\n<p>print(f&quot;OS Version: {os_version}&quot;)<\/p>\n<p>print(f&quot;Processor: {processor_info}&quot;)<\/p>\n<p>print(&quot;CPU Info (os.popen):&quot;)<\/p>\n<p>print(cpu_info_os)<\/p>\n<p>print(&quot;CPU Info (subprocess):&quot;)<\/p>\n<p>print(result.stdout)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u5728Python\u4e2d\u8f7b\u677e\u83b7\u53d6\u5230\u6240\u9700\u7684CPU\u4fe1\u606f\u3002\u8fd9\u4e9b\u4fe1\u606f\u5bf9\u4e8e\u6027\u80fd\u76d1\u63a7\u3001\u7cfb\u7edf\u5206\u6790\u4ee5\u53ca\u5f00\u53d1\u7cfb\u7edf\u76f8\u5173\u7684\u5e94\u7528\u7a0b\u5e8f\u90fd\u975e\u5e38\u6709\u7528\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u83b7\u53d6CPU\u4fe1\u606f\uff0c\u5e76\u7ed3\u5408\u5176\u4ed6\u7cfb\u7edf\u4fe1\u606f\u8fdb\u884c\u66f4\u6df1\u5165\u7684\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u83b7\u53d6CPU\u7684\u57fa\u672c\u4fe1\u606f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>platform<\/code>\u6a21\u5757\u548c<code>psutil<\/code>\u5e93\u6765\u83b7\u53d6CPU\u7684\u57fa\u672c\u4fe1\u606f\u3002<code>platform<\/code>\u6a21\u5757\u53ef\u4ee5\u63d0\u4f9b\u7cfb\u7edf\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u800c<code>psutil<\/code>\u5219\u53ef\u4ee5\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684CPU\u4f7f\u7528\u60c5\u51b5\u548c\u6027\u80fd\u6307\u6807\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5<code>psutil<\/code>\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4 <code>pip install psutil<\/code> \u6765\u5b8c\u6210\u3002\u83b7\u53d6CPU\u4fe1\u606f\u7684\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import platform\nimport psutil\n\n# \u83b7\u53d6CPU\u7684\u903b\u8f91\u6838\u5fc3\u6570\u91cf\ncpu_count = psutil.cpu_count(logical=True)\n# \u83b7\u53d6CPU\u7684\u7269\u7406\u6838\u5fc3\u6570\u91cf\nphysical_cpu_count = psutil.cpu_count(logical=False)\n# \u83b7\u53d6CPU\u7684\u9891\u7387\ncpu_freq = psutil.cpu_freq()\n\nprint(f&quot;\u903b\u8f91\u6838\u5fc3\u6570\u91cf: {cpu_count}&quot;)\nprint(f&quot;\u7269\u7406\u6838\u5fc3\u6570\u91cf: {physical_cpu_count}&quot;)\nprint(f&quot;CPU\u9891\u7387: {cpu_freq.current} MHz&quot;)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u4f7f\u7528Python\u76d1\u6d4bCPU\u7684\u5b9e\u65f6\u4f7f\u7528\u7387\uff1f<\/strong><br \/>\u901a\u8fc7<code>psutil<\/code>\u5e93\uff0c\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u76d1\u6d4bCPU\u7684\u5b9e\u65f6\u4f7f\u7528\u7387\u3002\u53ef\u4ee5\u4f7f\u7528<code>psutil.cpu_percent(interval=1)<\/code>\u65b9\u6cd5\u6765\u83b7\u53d6CPU\u7684\u4f7f\u7528\u7387\uff0c<code>interval<\/code>\u53c2\u6570\u6307\u5b9a\u4e86\u6d4b\u91cf\u7684\u65f6\u95f4\u95f4\u9694\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import psutil\n\n# \u83b7\u53d6CPU\u4f7f\u7528\u7387\uff0c\u95f4\u96941\u79d2\ncpu_usage = psutil.cpu_percent(interval=1)\nprint(f&quot;\u5f53\u524dCPU\u4f7f\u7528\u7387: {cpu_usage}%&quot;)\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u83b7\u53d6CPU\u7684\u6e29\u5ea6\u548c\u5176\u4ed6\u786c\u4ef6\u4fe1\u606f\uff1f<\/strong><br \/>\u83b7\u53d6CPU\u7684\u6e29\u5ea6\u901a\u5e38\u9700\u8981\u4f9d\u8d56\u4e8e\u7279\u5b9a\u7684\u5e93\uff0c\u5982<code>py-cpuinfo<\/code>\u6216<code>OpenHardwareMonitor<\/code>\u3002<code>py-cpuinfo<\/code>\u80fd\u591f\u63d0\u4f9bCPU\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u578b\u53f7\u3001\u67b6\u6784\u7b49\uff0c\u4f46\u8981\u83b7\u53d6\u6e29\u5ea6\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528<code>OpenHardwareMonitor<\/code>\u7b49\u5de5\u5177\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528<code>py-cpuinfo<\/code>\u83b7\u53d6CPU\u4fe1\u606f\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import cpuinfo\n\n# \u83b7\u53d6CPU\u4fe1\u606f\ncpu_info = cpuinfo.get_cpu_info()\nprint(cpu_info)\n<\/code><\/pre>\n<p>\u8981\u83b7\u53d6\u6e29\u5ea6\u4fe1\u606f\uff0c\u53ef\u80fd\u9700\u8981\u989d\u5916\u7684\u6b65\u9aa4\uff0c\u4f8b\u5982\u5b89\u88c5\u5e76\u914d\u7f6e\u76f8\u5173\u76d1\u6d4b\u5de5\u5177\u5e76\u901a\u8fc7Python\u8c03\u7528\u5176\u63a5\u53e3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a\u5728Python\u4e2d\uff0c\u8bfb\u53d6CPU\u4fe1\u606f\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528psutil\u5e93\u3001platform\u6a21\u5757\u3001os\u6a21\u5757\u7b49\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":991863,"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\/991857"}],"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=991857"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/991857\/revisions"}],"predecessor-version":[{"id":991866,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/991857\/revisions\/991866"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/991863"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=991857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=991857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=991857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}