简体   繁体   English

Windows 上的 Python - conhost.exe CPU 使用率

[英]Python on windows - conhost.exe CPU usage

I'm running a Python script on Windows, and I've noticed that even though the Python process takes ~8% CPU, the associated conhost.exe process takes ~14%.我在 Windows 上运行 Python 脚本,我注意到即使 Python 进程占用 ~8% CPU,关联的conhost.exe进程占用 ~14%。

Why is this so?为什么会这样? How come such a large part of the CPU consumption is in the conhost and not in the Python process?为什么 CPU 消耗的很大一部分是在主机而不是 Python 进程中?
Is there a way to reduce this CPU consumption?有没有办法减少这种 CPU 消耗? (besides optimizing the code of course) (当然除了优化代码)

UPDATE 1: Win7 64bit, Python 2.6.6更新 1: Win7 64 位,Python 2.6.6

UPDATE 2: The Python program uses a C++ package via SWIG Python bindings.更新 2: Python 程序通过SWIG Python 绑定使用 C++ 包。 The C++ package ( quickfix ) does I/O with the network quite a bit (1), it also prints to the console (2). C++ 包 ( quickfix ) 与网络进行了相当多的 I/O (1),它还打印到控制台 (2)。 The Python code prints to several files (3). Python 代码打印到多个文件 (3)。 Which if these three should be suspect?如果这三个应该怀疑哪个?

Since we don't know what your program is doing we have to guess a little.因为我们不知道你的程序在做什么,所以我们不得不猜测一下。 So long as there is no I/O I'd expect conhost to consume 0% CPU.只要没有 I/O,我就希望conhost消耗 0% 的 CPU。 So I hypothesise that you are printing a lot of text to the console.所以我假设您正在向控制台打印大量文本。 For example, the following program has the same symptoms as you report:例如,以下程序与您报告的症状相同:

while True:
    print "Hello world!"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM