Random high CPU usage with a minimal loop

Bug #1314377 reported by João Pinto
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pygame (Ubuntu)
New
Undecided
Unassigned

Bug Description

I have found this issue while developing a small game. I have now tested with a minimal pygame loop and the problem can be reproduced (randomly).
After a few minutes running the python process CPU usage from the running pygame loop jumps from <10% to >=100%.
The gdb trace info when it happens:

(gdb) thread apply all bt

Thread 3 (Thread 0x7f32117a4700 (LWP 5405)):
#0 0x00007f3220572b9d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007f321f2a64b9 in SDL_Delay (ms=<optimised out>) at ./src/timer/unix/SDL_systimer.c:118
#2 0x00007f321f2a64f2 in RunTimer (unused=0x7f32117a3ea0, unused@entry=0x0) at ./src/timer/unix/SDL_systimer.c:203
#3 0x00007f321f264ae8 in SDL_RunThread (data=0x1ebb7c0) at ./src/thread/SDL_thread.c:204
#4 0x00007f321f2a4079 in RunThread (data=<optimised out>) at ./src/thread/pthread/SDL_systhread.c:47
#5 0x00007f322056b182 in start_thread (arg=0x7f32117a4700) at pthread_create.c:312
#6 0x00007f322029830d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 2 (Thread 0x7f320c988700 (LWP 5407)):
#0 0x00007f321eb367a0 in pa_mainloop_poll () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#1 0x00007f321eb36ece in pa_mainloop_iterate () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#2 0x00007f321f288a9b in PULSE_WaitAudio (this=0x1f25ed0) at ./src/audio/pulse/SDL_pulseaudio.c:310
#3 0x00007f321f25c8f0 in SDL_RunAudio (audiop=audiop@entry=0x1f25ed0) at ./src/audio/SDL_audio.c:222
#4 0x00007f321f264ae8 in SDL_RunThread (data=0x1f2c060) at ./src/thread/SDL_thread.c:204
#5 0x00007f321f2a4079 in RunThread (data=<optimised out>) at ./src/thread/pthread/SDL_systhread.c:47
#6 0x00007f322056b182 in start_thread (arg=0x7f320c988700) at pthread_create.c:312
#7 0x00007f322029830d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 1 (Thread 0x7f3220981740 (LWP 5404)):
#0 0x00007f3220572b9d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007f321f2a64b9 in SDL_Delay (ms=<optimised out>) at ./src/timer/unix/SDL_systimer.c:118
#2 0x00007f321841d9e7 in ?? () from /usr/lib/python2.7/dist-packages/pygame/time.so
#3 0x000000000052c6d5 in PyEval_EvalFrameEx ()
#4 0x000000000052cf32 in PyEval_EvalFrameEx ()
#5 0x000000000052cf32 in PyEval_EvalFrameEx ()
#6 0x000000000052cf32 in PyEval_EvalFrameEx ()
#7 0x000000000055c594 in PyEval_EvalCodeEx ()
#8 0x00000000005b7392 in PyEval_EvalCode ()
#9 0x0000000000469663 in ?? ()
#10 0x00000000004699e3 in PyRun_FileExFlags ()
#11 0x0000000000469f1c in PyRun_SimpleFileExFlags ()
#12 0x000000000046ab81 in Py_Main ()
#13 0x00007f32201beec5 in __libc_start_main (main=0x46ac3f <main>, argc=2, argv=0x7fff35faed48, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fff35faed38) at libc-start.c:287
#14 0x000000000057497e in _start ()

When this happens, attempting to quit the process will hang it:
(gdb) thread apply all bt

Thread 3 (Thread 0x7f32117a4700 (LWP 5405)):
#0 0x00007f3220572b9d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007f321f2a64b9 in SDL_Delay (ms=<optimised out>) at ./src/timer/unix/SDL_systimer.c:118
#2 0x00007f321f2a64f2 in RunTimer (unused=0x7f32117a3ea0, unused@entry=0x0) at ./src/timer/unix/SDL_systimer.c:203
#3 0x00007f321f264ae8 in SDL_RunThread (data=0x1ebb7c0) at ./src/thread/SDL_thread.c:204
#4 0x00007f321f2a4079 in RunThread (data=<optimised out>) at ./src/thread/pthread/SDL_systhread.c:47
#5 0x00007f322056b182 in start_thread (arg=0x7f32117a4700) at pthread_create.c:312
#6 0x00007f322029830d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 2 (Thread 0x7f320c988700 (LWP 5407)):
#0 0x00007f321eb245ec in pa_context_get_state () from /usr/lib/x86_64-linux-gnu/libpulse.so.0
#1 0x00007f321f288ac4 in PULSE_WaitAudio (this=0x1f25ed0) at ./src/audio/pulse/SDL_pulseaudio.c:308
#2 0x00007f321f25c8f0 in SDL_RunAudio (audiop=audiop@entry=0x1f25ed0) at ./src/audio/SDL_audio.c:222
#3 0x00007f321f264ae8 in SDL_RunThread (data=0x1f2c060) at ./src/thread/SDL_thread.c:204
#4 0x00007f321f2a4079 in RunThread (data=<optimised out>) at ./src/thread/pthread/SDL_systhread.c:47
#5 0x00007f322056b182 in start_thread (arg=0x7f320c988700) at pthread_create.c:312
#6 0x00007f322029830d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 1 (Thread 0x7f3220981740 (LWP 5404)):
#0 0x00007f322056c66b in pthread_join (threadid=139852936414976, thread_return=thread_return@entry=0x0) at pthread_join.c:92
#1 0x00007f321f2a419b in SDL_SYS_WaitThread (thread=thread@entry=0x1f33230) at ./src/thread/pthread/SDL_systhread.c:107
#2 0x00007f321f264cd6 in SDL_WaitThread (thread=0x1f33230, status=status@entry=0x0) at ./src/thread/SDL_thread.c:272
#3 0x00007f321f25d07a in SDL_AudioQuit () at ./src/audio/SDL_audio.c:629
#4 0x00007f321f25bf95 in SDL_QuitSubSystem (flags=16) at ./src/SDL.c:190
#5 0x00007f3216fbcd55 in Mix_CloseAudio () at mixer.c:1145
#6 0x00007f3215570706 in ?? () from /usr/lib/python2.7/dist-packages/pygame/mixer.so
#7 0x00007f321f4e9f6a in ?? () from /usr/lib/python2.7/dist-packages/pygame/base.so
#8 0x00007f321f4e9fa9 in ?? () from /usr/lib/python2.7/dist-packages/pygame/base.so
#9 0x000000000052f936 in PyEval_EvalFrameEx ()
#10 0x000000000056d0aa in ?? ()
#11 0x00000000004da29f in PyEval_CallObjectWithKeywords ()
#12 0x000000000042fa19 in Py_Finalize ()
#13 0x000000000046ac10 in Py_Main ()
#14 0x00007f32201beec5 in __libc_start_main (main=0x46ac3f <main>, argc=2, argv=0x7fff35faed48, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fff35faed38) at libc-start.c:287
#15 0x000000000057497e in _start ()

The hang-on-quit behavior seems to be the issue described at:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=708760

Description: Ubuntu 14.04 LTS

Revision history for this message
João Pinto (joaopinto) wrote :

Adding the script used to reproduce the problem.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.