I'm writing a music player, to be able to control the music reading, I create a thread in which I put a while loop. My problem is that even if I limitate the loop with pyglet.clock.tick(), my cpu is at 100%.
Is there a way to reduce it ?
class PlayerThread(threading.Thread):
stopnow = None
player = None
def __init__(self, player, file_path):
threading.Thread.__init__(self)
self.stopnow = threading.Event()
self.player = player
source = pyglet.media.load(file_path)
self.player.queue(source)
def run(self):
self.play()
while not self.stopnow.isSet():
pyglet.clock.tick()
def play(self):
if not self.player.playing:
self.player.play()
def stop(self):
self.stopnow.set()
def pause(self):
if self.player.playing:
self.player.pause()
Thank you for your answer.
You have to use clock.set_fps_limit(number_of_frames_per_second)
to set upper bound of framerate.