You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue №331 opened by illume at 2017-03-13 17:53:23
Originally reported by: Maksym Planeta (Bitbucket: mplaneta, GitHub: mplaneta)
Hello,
I have a following snippet of code:
# !python
pygame.init()
import time
time.sleep(50)
When the scripts goes sleep, I observe high CPU utilization.
I tracked this down to sound system, and when I add pygame.mixer.quit() after init, script utilizes CPU as expected. I figured out that pygame creates a new process, which eats up all the CPU and the backtrace of this thread looks as follows (this is how I pointed problem to sound mixer):
(gdb) bt
# 0 0x00007f297504554d in poll () at ../sysdeps/unix/syscall-template.S:84
# 1 0x00007f295e16107e in ?? () from /usr/lib/x86_64-linux-gnu/libasound.so.2
# 2 0x00007f295e165fb8 in ?? () from /usr/lib/x86_64-linux-gnu/libasound.so.2
# 3 0x00007f295e1a60c8 in ?? () from /usr/lib/x86_64-linux-gnu/libasound.so.2
# 4 0x00007f29748c9fc5 in ALSA_PlayAudio (this=0x5633de70d990) at ./src/audio/alsa/SDL_alsa_audio.c:321
# 5 0x00007f297489ed90 in SDL_RunAudio (audiop=audiop@entry=0x5633de70d990) at ./src/audio/SDL_audio.c:215
# 6 0x00007f29748a6f58 in SDL_RunThread (data=0x5633de686360) at ./src/thread/SDL_thread.c:204
# 7 0x00007f29748e79d9 in RunThread (data=<optimized out>) at ./src/thread/pthread/SDL_systhread.c:47
# 8 0x00007f2975e5a424 in start_thread (arg=0x7f295622e700) at pthread_create.c:333
# 9 0x00007f297504e9bf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:105
Original comment byThomas Kluyver (Bitbucket: takluyver, GitHub: takluyver):
I can reproduce this if I install from a wheel from PyPI, but not if I install pygame from source. That points to some error with the packaging - maybe an issue with the old ALSA library that it's built with. Possibly we need to try building a newer version of ALSA from source.
I have exactly the same problem running Pygame 1.9.3 with Python 3.5.2 under Ubuntu 1.6.04 LTS. All I have to do is pygame.init() and the CPU utilization shoots up drastically. I tried following this with pygame.mixer.quit() but it made no difference. I believe I installed Python using PIP3.
Just wondering if you have made any progress on the issue and/or have any ideas on what I should do?
I also have this behavior on a pi, however the pygame.mixer.quit() does not resolve the problem. Does anyone have a good link on building from source on raspbian?
@steckelj One solution was maybe to not use pygame.init(). Are you using this? If so, try not doing so. Instead, do pygame.___.init() for any modules that are required. Such as pygame.display.init() and pygame.mixer.init() and pygame.font.init(). If you are interested see https://github.com/Roland00111/Trumpocalypse/blob/master/UI/Trumpocalypse.py for implementation.
I am actually only using pygame.display.init(). I read many guides on the high CPU utilization before I posted on the issue here, and I have no loop and am just sitting at pygame.event.wait() with no allowed events and have near 100% CPU. No other updating. Is it possible I'm not experiencing the same issue?
I'll have to try a test pygame.display.init() only and see if I get the same thing.
I did find what looks to be good instructions for building from source, see pygame section here: http://elinux.org/RPi_Debian_Python3
(I have yet to test the instructions)
I had been through all of that above - definitely thought it was me for two weeks before I arrived here at this bug and read through everything I could find. I actually eliminated any loop entirely to be sure it wasn't that.
However, I will better confirm I am experiencing this issue before I post anything further here.
I believe I can now confirm this is happening even if you only init the display. Can anyone suggest a previous version I can use? Will that avoid the problem?
The following code produces near 100% CPU on a Pi:
Adding the pygame.mixer.quit() also doesn't help (I didn't init it anyhow). I also tried removing pygame and compiling from source via the following but still experience the same issue. The instructions below specified that sound had been removed.
I think there are a couple of different bugs in play here; the original one reported appeared to be only an issue with the pre-built wheels, and went away when I built pygame from source on the target system. The new one doesn't. Unfortunately I don't have any recommendations for either right now.
Hi I have the same issue on Arch-Linux and I can fix it with not initializing the mixer module.
Some Version info that could be important:
Python 3.6.3
pygame==1.9.3 (from pip! It works with the arch packaged pygame 1.9.3)
sdl 1.2.15-9
portmidi 217-5
sdl_image 1.2.12-4
sdl_ttf 2.0.11-4
sdl_mixer 1.2.12-5
CPU usage jumps to 90% after mixer.init() and decreases right after mixer.quit()
Off-topic... any Idea why I don't have /usr/local/lib/python2.7/dist-packages in sys.path by default and so I have to append it explicitly before I can use pygame?
This is a fluidinfo/pulseaudio/SDL_mixer issue, and best addressed there.
We have the option of not including fluidsynth, but then music wouldn't work for some people.
App side, a work around of using alsa SDL audio driver with an environment variable, or not initialising the music mixer if not using it.
Same issue here on Manjaro with Python 3.6.4. Got around 25% CPU usage with sampled script when using pygame 1.9.3 installed using pip. When switched to pygame 1.9.3-2 builded from Arch's source repositories everything looks fine - CPU workload drops to ~1%.
From: iErcan [email protected]
Sent: Monday, May 21, 2018 3:26:06 PM
To: pygame/pygame
Cc: Subscribed
Subject: Re: [pygame/pygame] High CPU usage in pygame (# 331)
same issue with Debian 9.4, i have 25% CPU usage with the most basic pygame script possible
Can confirm same results, and using pygame.display.init() instead of pygame.init() or pygame.mixer.quit() after pygame.init() seems to have solved the high CPU problem for me. Also, I followed all the steps exactly from the manual compile page, but still get an error on install, is there a problem with that?
OSX High Sierra, pygame==1.9.5.dev0, anaconda python 3.6.
Installing from source, either github, or homebrew, doesn't work, pygame.display.init() doesn't work, pygame.mixer.quit() doesn't work -- just goes straight to 100% CPU.
EDIT: BUT -- and I don't know if this is feasible with other people's applications, but -- the second I switched from using pygame.event.get() to pygame.event.wait(), usage dropped from 100% to 6%. I assume most people have more events than I do, but it has also been the only thing that worked.
Yeah, it's a sdl_mixer issue for sure. I think it's to do with the SDL and SDL_mixer that are linked in the wheel. As you and other people state: the issue does not appear with Arch linux compiled SDL and pygame, or when you compile pygame from source and link against the Arch linux supplied dependencies.
I feel we might be able to apply all the patches that arch linux does (and more), and this would fix the issue.
See the issue here which is about applying the patches: pygame/pygame#497
If you feel like making the wheels yourself, please see in the pygame repo, the instructions and scripts to automate building it all are there: buildconfig/manylinux-build/
If none of the patches fix the issue, then it may be to do with config, or even some sort of ABI incompatibility of the ancient linux that the manylinux wheels are made on.
I'm quite surprised to see such a major issue unchanged after so long. I started using pygame about 6 months ago but stuck with the 1.9.1 version included with Linux Mint 18.3 because of this performance issue. At the time I suspected it was blitting or some such thing that drove my CPU usage up to 20%. As I neared the release of my pygames, I did more testing and found that 1 of my 8 cores is at 100% despite the blitting speed being higher in 1.9.4.
Calling mixer.quit() does alleviate the problem, but neither silence nor rapid battery drain are acceptable so I must stick with 1.9.1. Perhaps changing the driver to ALSA in an environment variable would work as one user suggested, but he gave no instructions. The increased blitting speed I measured i 1.9.4 is completely wasted because the recent versions are broken in Linux.
The following measurements were taken from the tottime column after running the following command: 'python2 -m cProfile run_game.py >profile.txt'. The longer time spent in pygame.clock.tick() suggests to me that pygame's efficiency significantly increased. All my physics, collision, AI and other logic uses less than 0.5% of the total time according to cProfile.
1.9.1 1.9.4
CPU use 7% 20% -> ouch, bye-bye battery and a hot lap
tick() 59.5% 85.6%
blit() 29.4% 9.4%
flip() 11.1% 5%
Hey I have the same issue. When I start pygame, whatever the code I'm running it uses one of my core at 100%.
I'm using arch with Gnome (also tested on Linux Mint 17 cinnamon and on Windows 10) & pygame (1.9.4) as well as python 3.7.2. I've always installed pygame with pip. I've also tried to run my game with previous version of pygame (1.9.3 & 1.8) and python (3.5) and I always get the same deceiving results.
A working hack for me is to quit the mixer after initializing pygame. Instead of 8.33% CPU (one full core) I get 0.2% of CPU usage from my game. However I'd like to add some sound in my game and wonder how I could do this while keeping acceptable performance.
If you need any additional information or help to try out things don't hesitate to ask.
My games run at about 8% cpu with sound. They use pygame 1.9.1 on python
2.7 or 3.5. Pygame 1.9.1 is the version included with Linux Mint 18.3. Not
sure where else you can get it.
Check out Cooties and Flyboy. The sourcce code is not available there but I
can send it if you're interested
Hey I have the same issue. When I start pygame, whatever the code I'm
running it uses one of my core at 100%.
I'm using arch with Gnome (also tested on Linux Mint 17 cinnamon) & pygame
(1.9.4) as well as python 3.7.2. I've also tried to run my game with
previous version of pygame and python and I always get the same deceiving
results.
A working hack for me is to quit the mixer after initializing pygame.
Instead of 8.33% CPU (one full core) I get 0.2% of CPU usage from my game.
However I'd like to add some sound in my game and wonder how I could do
this while keeping acceptable performance.
If you need any additional information or help to try out things don't
hesitate to ask.
Thank's. But does not work for me, one CPU is still on 100%.
This is my code (included the hints since 2017):
import pygame
from pygame.locals import *
import time
def run_game():
pygame.init();
pygame.mixer.quit();
screen = pygame.display.set_mode((400, 100));
clock = pygame.time.Clock();
clock.tick(1);
# Main loop for the game
while True:
# time.sleep(1);
# if you comment out the sleep and comment out the following: no cpu problem!
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(5);
pygame.display.flip();
run_game()```
The output is
```pygame 2.0.0.dev2 (SDL 2.0.9, python 3.6.8)
Hello from the pygame community. https://www.pygame.org/contribute.html
<hr>
# # # **[s0lst1ce](https://github.com/s0lst1ce)* commented at 2019-06-21 12:13:28*
Well you quit the mixer when you've just initialized pygame. Are you sure this is related to the mixer ? To me it sounds like the problem is due to the `clock.tick(1)` being outside your while loop Thus it will try to run as many times as possible. I think this is the issue. After trying and correcting this code using this advice it ran fine on my computer @mobariza
<hr>
# # # **[notpygame](https://github.com/notpygame)* commented at 2019-06-21 12:37:03*
@mobariza Adding a clock.tick(60) into the loop should fix that so it can only run 60fps.
<hr>
# # # **[mobariza](https://github.com/mobariza)* commented at 2019-06-21 15:33:12*
@notpygame This works fine, thank you a lot!
Anyway a suggestion: This is a hard-to-find error for pygame-newbies like me; the solution does not work if the tick() is outside the while neither if it is inside the for-loop. Maybe a good idea to set the variable by default to a reasonable value, user won't burn her finger on the laptop by trying the most simple pygame-excercise?
By the way, I am not able to raise the one CPU to 100% by *any* setting of the clock, even by a setting ```clock.tick(1.000.000.000.000.000)```(without dots), it is then still near 40%; maybe still a deeper problem around this?
<hr>
# # # **[s0lst1ce](https://github.com/s0lst1ce)* commented at 2019-06-21 15:59:16*
@mobariza If you need more help you should probably ask it on the [discord](https://discord.gg/guQbrW) server where many will be glad to help you. Using this unrelated issue as a discussion thread really isn't the best idea ;). Also the docs clearly explain how `clock.tick()` works. Why would you want to use 100% of your core ?
<hr>
# # # **[mobariza](https://github.com/mobariza)* commented at 2019-06-22 00:10:01*
@NotaSmartDev Thank you, my problem is completely solved, thanks to the help of notpygame. And sorry for the misunderstanding. Hunting bugs, I personally appreciate always hints, and as such my test with large numbers to tick() was meant. Nobody wants a 100% CPU usage; but if the setting to an extraordinary high value results in a lower usage as *no* value set, seems to be at least strange and worth for further examination.
And sorry for the suggestion to set hardcoded a reasonable value to avoid the 100% CPU usage, what nobody wants, including me and all the others coding the first lines with pygame. I thought the one who fixed the bug (notpygame) was a good address to tell.
<hr>
# # # **[mcpalmer1980](https://github.com/mcpalmer1980)* commented at 2019-07-13 13:09:42*
I would love to try out the pygame2-dev on my Linux Mint Mate 18.3 machine
but I cannot. When trying to install with pip I get a sdl-config failure. I
tried to install libsdl-dev but apt cannot resolve dependencies. There
doesn't seem to be an libsdl2-dev package in my distribution, or perhaps
libsdl-dev includes sdl2.
I'm eagerly waiting to try pygame2 the instant somebody builds a compatible
package. In the meant time pygame1.9.1 on python2 is working fine for my
projects except for the damn joystick debug info printing to my console 300
times per second. A problem fixed in newer versions that include the bug
discussed on this thread.
On Thu, Jun 20, 2019 at 10:38 AM notpygame <[email protected]> wrote:
> Hi,
>
> can someone with the issue on Linux please try out the latest pre-release?
> It uses SDL2, and a different audio backend.
>
> python3 -m pip install pygame==2.0.0.dev2 --user
>
> cheers!
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pygame/pygame/issues/331?email_source=notifications&email_token=ALHMW2E5DCDSCDCQUHEPPJ3P3OI4VA5CNFSM4DKFR4R2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYFTQXA# issuecomment-504051804>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ALHMW2EFH6HZ6XV2YGSIG2LP3OI4VANCNFSM4DKFR4RQ>
> .
>
<hr>
# # # **[illume](https://github.com/illume)* commented at 2019-07-13 14:00:01*
@mcpalmer1980 did you try this?
~~```python3 -m pip install --pre "pygame>=2.0.0.dev1" --user `~~
---
Edit: pygame 2 has been released now.
python3 -m pip install pygame
For the best up to date install instructions see: https://www.pygame.org/wiki/GettingStarted
---
Otherwise I think you can install from source... http://www.pygame.org/wiki/CompileUbuntu# pygame%20with%20sdl2%20(alpha)
<hr>
# # # **[nurettin](https://github.com/nurettin)* commented at 2019-07-23 20:45:52*
I confirm this as being fixed. High CPU usage when I do `pygame.init()` is now gone on pygame 2.0.0.dev3.
<hr>
# # # **[flaschbier](https://github.com/flaschbier)* commented at 2019-08-23 17:33:15*
@notpygame still > 35% cpu with pygame 1.9.6 on a Mac and `clock.tick(60)`. So why do you close this issue?
<hr>
# # # **[s0lst1ce](https://github.com/s0lst1ce)* commented at 2019-08-23 22:53:41*
Because as it was mentioned this is only fixed with pygame2 @flaschbier
<hr>
# # # **[ghost](https://github.com/ghost)* commented at 2019-10-15 13:54:08*
> @steckelj One solution was maybe to not use pygame.init(). Are you using this? If so, try not doing so. Instead, do pygame.___.init() for any modules that are required. Such as pygame.display.init() and pygame.mixer.init() and pygame.font.init(). If you are interested see https://github.com/Roland00111/Trumpocalypse/blob/master/UI/Trumpocalypse.py for implementation.
Worked for my case.
<hr>
# # # **[ravish0007](https://github.com/ravish0007)* commented at 2020-01-16 06:29:40*
This one helped a lot, Incredible !
<hr>
# # # **[k0mmsussert0d](https://github.com/k0mmsussert0d)* commented at 2020-04-13 16:27:59*
Unfortunately, I'm experiencing this behavior on `2.0.0.dev6` version :(
<hr>
# # # **[s0lst1ce](https://github.com/s0lst1ce)* commented at 2020-04-13 21:05:49*
@k0mmsussert0d are you sure your code uses correct pygame logic? For more help I would advise to follow my previous comment [recommendations](https://github.com/pygame/pygame/issues/331# issuecomment-504478446). Otherwise seeing your code would be essential in order to help you.
The text was updated successfully, but these errors were encountered:
Issue №331 opened by illume at 2017-03-13 17:53:23
Originally reported by: Maksym Planeta (Bitbucket: mplaneta, GitHub: mplaneta)
Hello,
I have a following snippet of code:
When the scripts goes sleep, I observe high CPU utilization.
I tracked this down to sound system, and when I add pygame.mixer.quit() after init, script utilizes CPU as expected. I figured out that pygame creates a new process, which eats up all the CPU and the backtrace of this thread looks as follows (this is how I pointed problem to sound mixer):
Python version: 3.5.3
libasound2 version: 1.1.3-4 (Debian testing)
Comments
# # illume commented at 2017-03-13 21:33:43
Original comment by Thomas Kluyver (Bitbucket: takluyver, GitHub: takluyver):
I can reproduce this if I install from a wheel from PyPI, but not if I install pygame from source. That points to some error with the packaging - maybe an issue with the old ALSA library that it's built with. Possibly we need to try building a newer version of ALSA from source.
# # illume commented at 2017-03-18 11:09:05
Original comment by Thomas Kluyver (Bitbucket: takluyver, GitHub: takluyver):
I was hoping building with a newer version of ALSA (pull request https://bitbucket.org/pygame/pygame/pull-requests/77/build-alsa-lib-ourselves-in-docker-base/diff) would fix this, but it does not seem to, unfortunately. I'm not sure what else to try.
# # astronerdnj commented at 2017-05-05 01:02:56
Hi there,
I have exactly the same problem running Pygame 1.9.3 with Python 3.5.2 under Ubuntu 1.6.04 LTS. All I have to do is pygame.init() and the CPU utilization shoots up drastically. I tried following this with pygame.mixer.quit() but it made no difference. I believe I installed Python using PIP3.
Just wondering if you have made any progress on the issue and/or have any ideas on what I should do?
Thanks
# # takluyver commented at 2017-05-05 09:45:57
I think you can work round it by building pygame yourself from source. I haven't made any progress in working out what the problem is.
# # davidshumway commented at 2017-05-06 15:17:24
Noticing this behavior as well: Roland00111/Trumpocalypse#18.
# # steckelj commented at 2017-05-18 19:14:41
I also have this behavior on a pi, however the pygame.mixer.quit() does not resolve the problem. Does anyone have a good link on building from source on raspbian?
# # davidshumway commented at 2017-05-18 19:19:03
@steckelj One solution was maybe to not use pygame.init(). Are you using this? If so, try not doing so. Instead, do pygame.___.init() for any modules that are required. Such as pygame.display.init() and pygame.mixer.init() and pygame.font.init(). If you are interested see https://github.com/Roland00111/Trumpocalypse/blob/master/UI/Trumpocalypse.py for implementation.
# # steckelj commented at 2017-05-18 19:25:05
I am actually only using pygame.display.init(). I read many guides on the high CPU utilization before I posted on the issue here, and I have no loop and am just sitting at pygame.event.wait() with no allowed events and have near 100% CPU. No other updating. Is it possible I'm not experiencing the same issue?
I'll have to try a test pygame.display.init() only and see if I get the same thing.
I did find what looks to be good instructions for building from source, see pygame section here: http://elinux.org/RPi_Debian_Python3
(I have yet to test the instructions)
# # davidshumway commented at 2017-05-18 19:29:27
Okay. Yes, for us it was similar. One solution was to use pygame.time.wait(0) in the while loop. See here: https://github.com/Roland00111/Trumpocalypse/blob/master/UI/eventsloop.py.
Where process_pygame_events() is a function where pygame.event.get() is looped through.
Another solution may be related to clock tick() or fps.
# # steckelj commented at 2017-05-18 19:34:33
I had been through all of that above - definitely thought it was me for two weeks before I arrived here at this bug and read through everything I could find. I actually eliminated any loop entirely to be sure it wasn't that.
However, I will better confirm I am experiencing this issue before I post anything further here.
# # steckelj commented at 2017-05-19 14:23:43
I believe I can now confirm this is happening even if you only init the display. Can anyone suggest a previous version I can use? Will that avoid the problem?
The following code produces near 100% CPU on a Pi:
import pygame
pygame.display.init()
pygame.event.set_allowed(None)
pygame.event.wait()
Adding the pygame.mixer.quit() also doesn't help (I didn't init it anyhow). I also tried removing pygame and compiling from source via the following but still experience the same issue. The instructions below specified that sound had been removed.
GET PYGAME SOURCE CODE
sudo apt-get install mercurial
hg clone https://bitbucket.org/pygame/pygame
cd pygame
INSTALL DEPENDENCIES
sudo apt-get install libsdl-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev
sudo apt-get install libsmpeg-dev libportmidi-dev libavformat-dev libswscale-dev
BUILD AND INSTALL PYGAME
python3 setup.py build
sudo python3 setup.py install
Any help to get around this for the moment would be much appreciated!
# # takluyver commented at 2017-05-19 14:34:32
I think there are a couple of different bugs in play here; the original one reported appeared to be only an issue with the pre-built wheels, and went away when I built pygame from source on the target system. The new one doesn't. Unfortunately I don't have any recommendations for either right now.
# # Duality4Y commented at 2017-10-28 14:31:21
I observed high cpu load too, from the package installed via pip,
but when i installed from source it was all fine.
# # nylocx commented at 2017-12-15 08:20:58
Hi I have the same issue on Arch-Linux and I can fix it with not initializing the mixer module.
Some Version info that could be important:
Python 3.6.3
pygame==1.9.3 (from pip! It works with the arch packaged pygame 1.9.3)
sdl 1.2.15-9
portmidi 217-5
sdl_image 1.2.12-4
sdl_ttf 2.0.11-4
sdl_mixer 1.2.12-5
# # VladMasarik commented at 2018-01-21 22:01:50
Hey there I seem to have same problem.
I used
python3 -m pip install pygame --user
to install pygame as said on pygame website.
CPU usage jumps to 90% after
mixer.init()
and decreases right aftermixer.quit()
Off-topic... any Idea why I don't have
/usr/local/lib/python2.7/dist-packages
insys.path
by default and so I have to append it explicitly before I can use pygame?# # illume commented at 2018-02-13 07:46:22
I noticed this issue with fluidsynth and pulseaudio. Worth investigating to see if this is the cause: FluidSynth/fluidsynth#338
# # illume commented at 2018-02-20 18:10:23
Another "high cpu" issue on Ubuntu launchpad, with pulse audio in the traceback https://bugs.launchpad.net/ubuntu/+source/pygame/+bug/1314377
# # illume commented at 2018-02-27 10:39:10
This is a fluidinfo/pulseaudio/SDL_mixer issue, and best addressed there.
We have the option of not including fluidsynth, but then music wouldn't work for some people.
App side, a work around of using alsa SDL audio driver with an environment variable, or not initialising the music mixer if not using it.
# # tomkc commented at 2018-02-28 23:44:34
Same issue here on Manjaro with Python 3.6.4. Got around 25% CPU usage with sampled script when using pygame 1.9.3 installed using pip. When switched to pygame 1.9.3-2 builded from Arch's source repositories everything looks fine - CPU workload drops to ~1%.
# # d4em0n commented at 2018-05-18 05:15:48
same issue with pygame 1.9.3, my cpu temperature goes up immediately
# # iErcann commented at 2018-05-21 14:26:04
same issue with Debian 9.4, i have 25% CPU usage with the most basic pygame script possible
# # oooobi commented at 2018-05-21 20:16:36
Like its seriously impossible.
Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10
From: iErcan [email protected]
Sent: Monday, May 21, 2018 3:26:06 PM
To: pygame/pygame
Cc: Subscribed
Subject: Re: [pygame/pygame] High CPU usage in pygame (# 331)
same issue with Debian 9.4, i have 25% CPU usage with the most basic pygame script possible
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<pygame/pygame#331 issuecomment-390669995>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AlZQOErp8gEZjAJZjqnqJTn0yFdUwa-mks5t0s5-gaJpZM4NRY8j.
# # ghost commented at 2018-06-23 13:54:53
Can confirm same results, and using pygame.display.init() instead of pygame.init() or pygame.mixer.quit() after pygame.init() seems to have solved the high CPU problem for me. Also, I followed all the steps exactly from the manual compile page, but still get an error on install, is there a problem with that?
# # amloewi commented at 2018-08-08 04:30:11
OSX High Sierra, pygame==1.9.5.dev0, anaconda python 3.6.
Installing from source, either github, or homebrew, doesn't work, pygame.display.init() doesn't work, pygame.mixer.quit() doesn't work -- just goes straight to 100% CPU.
EDIT: BUT -- and I don't know if this is feasible with other people's applications, but -- the second I switched from using
pygame.event.get()
topygame.event.wait()
, usage dropped from 100% to 6%. I assume most people have more events than I do, but it has also been the only thing that worked.# # e1000 commented at 2018-08-25 14:21:53
Hello,
I don't know if it helps, but on debian strech :
# # illume commented at 2018-08-25 14:47:39
@e1000 Good detective work.
Yeah, it's a sdl_mixer issue for sure. I think it's to do with the SDL and SDL_mixer that are linked in the wheel. As you and other people state: the issue does not appear with Arch linux compiled SDL and pygame, or when you compile pygame from source and link against the Arch linux supplied dependencies.
I feel we might be able to apply all the patches that arch linux does (and more), and this would fix the issue.
See the issue here which is about applying the patches: pygame/pygame#497
If you feel like making the wheels yourself, please see in the pygame repo, the instructions and scripts to automate building it all are there: buildconfig/manylinux-build/
If none of the patches fix the issue, then it may be to do with config, or even some sort of ABI incompatibility of the ancient linux that the manylinux wheels are made on.
# # mathias93 commented at 2018-11-24 01:10:30
Same issue installed 1.9.4 using pip, python 3.4 @ 100%CPU utilization
Confirmed on desktop Ryzen7 using python 3.5.3 as well
# # kooscode commented at 2018-12-09 21:33:55
same issue with python 3.6.3 and installed with pip3.
100% CPU pegged with this code..
but works perfect when calling pygame.mixer.quit like so..
# # SebastianJL commented at 2018-12-10 18:56:32
I appear to have the same problem.
2 cores have 100% usage if I use:
The cpu usage drops down to about 20% on only one core if i use:
# # mcpalmer1980 commented at 2019-01-28 11:43:00
I'm quite surprised to see such a major issue unchanged after so long. I started using pygame about 6 months ago but stuck with the 1.9.1 version included with Linux Mint 18.3 because of this performance issue. At the time I suspected it was blitting or some such thing that drove my CPU usage up to 20%. As I neared the release of my pygames, I did more testing and found that 1 of my 8 cores is at 100% despite the blitting speed being higher in 1.9.4.
Calling mixer.quit() does alleviate the problem, but neither silence nor rapid battery drain are acceptable so I must stick with 1.9.1. Perhaps changing the driver to ALSA in an environment variable would work as one user suggested, but he gave no instructions. The increased blitting speed I measured i 1.9.4 is completely wasted because the recent versions are broken in Linux.
The following measurements were taken from the tottime column after running the following command: 'python2 -m cProfile run_game.py >profile.txt'. The longer time spent in pygame.clock.tick() suggests to me that pygame's efficiency significantly increased. All my physics, collision, AI and other logic uses less than 0.5% of the total time according to cProfile.
# # s0lst1ce commented at 2019-02-20 13:44:55
Hey I have the same issue. When I start pygame, whatever the code I'm running it uses one of my core at 100%.
I'm using arch with Gnome (also tested on Linux Mint 17 cinnamon and on Windows 10) & pygame (1.9.4) as well as python 3.7.2. I've always installed pygame with pip. I've also tried to run my game with previous version of pygame (1.9.3 & 1.8) and python (3.5) and I always get the same deceiving results.
A working hack for me is to quit the mixer after initializing pygame. Instead of 8.33% CPU (one full core) I get 0.2% of CPU usage from my game. However I'd like to add some sound in my game and wonder how I could do this while keeping acceptable performance.
If you need any additional information or help to try out things don't hesitate to ask.
# # mcpalmer1980 commented at 2019-03-06 11:48:54
My games run at about 8% cpu with sound. They use pygame 1.9.1 on python
2.7 or 3.5. Pygame 1.9.1 is the version included with Linux Mint 18.3. Not
sure where else you can get it.
Check out Cooties and Flyboy. The sourcce code is not available there but I
can send it if you're interested
https://mcpalmer1980.itch.io/ https://mcpalmer1980.itch.io/
On Wed, Feb 20, 2019 at 8:44 AM 01g1n [email protected] wrote:
# # LJMP commented at 2019-06-14 06:04:40
seems finally fixed in version:
pip install "pygame>=2.0.0.dev1"
🎉
PS: running Linux 4.15.0-51-generic 16.04.1-Ubuntu
pygame 2.0.0.dev1 (SDL 1.2.15, python 2.7.12)
# # notpygame commented at 2019-06-20 14:37:55
Hi,
can someone with the issue on Linux please try out the latest pre-release?
It uses SDL2, and a different audio backend.
cheers!
# # s0lst1ce commented at 2019-06-20 19:28:04
Works for me. Good job !
# # mobariza commented at 2019-06-21 08:03:19
Thank's. But does not work for me, one CPU is still on 100%.
This is my code (included the hints since 2017):
python3 -m pip install pygame
The text was updated successfully, but these errors were encountered: