简体   繁体   English

为什么引用(python)pyglet.image中的类会导致Windows上的CPU负载过重?

[英]Why does referring to a class in (python) pyglet.image cause heavy cpu load on Windows?

I'm using python's pyglet module (python 3 on Windows). 我正在使用python的pyglet模块(Windows上的python 3)。 When I refer to any classes within pyglet.image, python's CPU usage jumps up and doesn't drop until I exit python. 当我引用pyglet.image中的任何类时,python的CPU使用率会跳起来并且在我退出python之前不会下降。 For example: 例如:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Anaconda3>python.exe
Python 3.4.3 |Anaconda 2.3.0 (64-bit)| (default, Mar  6 2015, 12:06:10) [MSC v.1
600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyglet #No problem!
>>> pyglet.image.ImageData #Heavy CPU load until I exit python
<class 'pyglet.image.ImageData'>

Is this expected behavior? 这是预期的行为吗? Why does mentioning this class (not even instantiating it) lead to such high CPU load? 为什么提这个类 (甚至没有实例化它) 导致如此高的CPU负载?

Systems I've tested: 我测试的系统:

  • Windows 7 desktop with Anaconda python 3.4.3 and pyglet installed through 'pip install pyglet': High CPU usage (my problem) 带有Anaconda python 3.4.3的Windows 7桌面和通过'pip install pyglet'安装的pyglet:高CPU使用率(我的问题)

  • The same Win7 desktop with Anaconda python 3.4.3, but pyglet installed through 'pip install hg+ https://bitbucket.org/pyglet/pyglet ': High CPU usage. 与Anaconda python 3.4.3相同的Win7桌面,但通过'pip install hg + https://bitbucket.org/pyglet/pyglet '安装了pyglet:高CPU使用率。

  • The same Win7 desktop with python 3.5 from python.org and pyglet installed through 'pip install pyglet': High CPU usage. 来自python.org的python 3.5的相同Win7桌面和通过'pip install pyglet'安装的pyglet:高CPU使用率。

  • Fedora 22 Lenovo laptop with python 3.4.2 and pyglet 1.2.1 installed through dnf: no problem. Fedora 22联想笔记本电脑用python 3.4.2和pyglet 1.2.1通过dnf安装:没问题。

  • Windows 10 HP laptop with Anaconda python 3.4 and pyglet installed through 'pip install pyglet': no problem. Windows 10惠普笔记本电脑与Anaconda python 3.4和pyglet通过'pip install pyglet'安装:没问题。

Is it possible this is hardware-dependent? 这是否可能与硬件有关?

It is probably related to the following lines on the module : 它可能与模块上的以下行有关:

# Initialise default codecs
from pyglet.image import codecs as _codecs
_codecs.add_default_image_codecs()

The order for loading the default codecs is: 加载默认编解码器的顺序是:

# Add the codecs we know about.  These should be listed in order of
# preference.  This is called automatically by pyglet.image.

# Compressed texture in DDS format
try:
    from pyglet.image.codecs import dds
    add_encoders(dds)
    add_decoders(dds)
except ImportError:
    pass

# Mac OS X default: QuickTime
(...)

# Windows XP default: GDI+
(...)

# Linux default: GdkPixbuf 2.0
(...)

# Fallback: PIL
(...)

# Fallback: PNG loader (slow)
(...)

# Fallback: BMP loader (slow)
(...)

Because of lazy loading pyglet.image is only loaded when you refer to something, and you are probably using one of the slow fallbacks. 由于延迟加载pyglet.image仅在您引用某些内容时加载,并且您可能正在使用其中一个缓慢的后备。 If that is the case maybe you can try installing/uninstalling the codecs so that you use one at a time and find out if the problem is indeed with the codecs. 如果是这种情况,也许你可以尝试安装/卸载编解码器,这样你就可以一次使用一个编解码器,并找出问题确实存在于编解码器中。 Posting your versions of these codecs may help reproduce the issue. 发布这些编解码器的版本可能有助于重现该问题。

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

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