Using pygame on Ubuntu 16.04 results in 100% CPU usage.
main.py
import time
import pygame
pygame.init()
while True:
time.sleep(1)
It is a code that does nothing, but if you check it on top
top
top - 13:18:43 up 6:21, 1 user, load average: 0.78, 0.56, 0.48
Tasks: 329 total, 1 running, 328 sleeping, 0 stopped, 0 zombie
%Cpu(s): 26.0 us, 4.8 sy, 0.6 ni, 68.2 id, 0.4 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 12222916 total, 5867808 free, 3502168 used, 2852940 buff/cache
KiB Swap: 12502012 total, 12502012 free, 0 used. 7608068 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18635 USER 20 0 704956 31568 18668 S 93.8 0.3 0:41.60 python2.7
1800 USER 20 0 1251136 113176 64712 S 6.2 0.9 6:27.81 compiz
1 root 20 0 119960 6064 3932 S 0.0 0.0 0:03.00 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.21 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+
7 root 20 0 0 0 0 S 0.0 0.0 0:09.43 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:00.09 migration/0
10 root rt 0 0 0 0 S 0.0 0.0 0:00.04 watchdog/0
11 root rt 0 0 0 0 S 0.0 0.0 0:00.04 watchdog/1
12 root rt 0 0 0 0 S 0.0 0.0 0:00.07 migration/1
13 root 20 0 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/1
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:+
16 root rt 0 0 0 0 S 0.0 0.0 0:00.04 watchdog/2
17 root rt 0 0 0 0 S 0.0 0.0 0:00.08 migration/2
18 root 20 0 0 0 0 S 0.0 0.0 0:00.24 ksoftirqd/2
You can see that Python occupies the CPU for a terrible time.
The environment is as follows. CPU:Core i3 4005u Memory:12G OS:Ubuntu 16.04(LTS)
Apparently pygame.init () is doing something wrong. According to the pygame documentation, pygame.init () seems to be a function that initializes multiple modules at once. Only the module specified by pygame. [module name] .init () can be initialized. So, when I initialized the modules individually, the CPU usage was 100% immediately after calling pygame.base.init (). Is this the cause?
Instead of writing pygame.init (), if there is a module that needs to be initialized, it will be initialized with pygame. [Module name] .init (). Fortunately, pygame.base doesn't seem to cause an error without initialization, so I solved it for the time being.
Recommended Posts