def _worker_func(self):
        thread = self._thread
        #buffered_time = 0
        eos = False
        events = self._events

        while True:
            thread.condition.acquire()
            if thread.stopped or (eos and not events):
                thread.condition.release()
                break

            # Use up "buffered" audio based on amount of time passed.
            timestamp = self.get_time()
            if _debug:
                print 'timestamp: %r' % timestamp

            # Dispatch events
            while events and events[0].timestamp <= timestamp:
                events[0]._sync_dispatch_to_player(self.player)
                del events[0]

            # Calculate how much data to request from source
            secs = self._packets_duration - self._buffer_time
            bytes = secs * self.source_group.audio_format.bytes_per_second
            if _debug:
                print 'Trying to buffer %d bytes (%r secs)' % (bytes, secs)

            while bytes > self._min_update_bytes and not eos:
                # Pull audio data from source
                audio_data = self.source_group.get_audio_data(int(bytes))
                if not audio_data and not eos:
                    events.append(MediaEvent(timestamp, 'on_eos'))
                    events.append(MediaEvent(timestamp, 'on_source_group_eos'))
                    eos = True
                    break
    
                # Pretend to buffer audio data, collect events.
                if self._playing and not self._packets:
                    self._timestamp_time = time.time()
                self._packets.append(SilentAudioPacket(audio_data.timestamp,
                                                       audio_data.duration))
                self._packets_duration += audio_data.duration
                for event in audio_data.events:
                    event.timestamp += audio_data.timestamp
                    events.append(event)
                events.extend(audio_data.events)
                bytes -= audio_data.length

            sleep_time = self._sleep_time
            if not self._playing:
                sleep_time = None
            elif events and events[0].timestamp and timestamp:
                sleep_time = min(sleep_time, events[0].timestamp - timestamp)

            if _debug:
                print 'SilentAudioPlayer(Worker).sleep', sleep_time
            thread.sleep(sleep_time)
            
            thread.condition.release()
dataset/ETHPy150Open ardekantur/pyglet/pyglet/media/drivers/silent.py/SilentAudioPlayerPacketConsumer._worker_func/swapped operands of `-`