def release_balls(self, balls_to_release):
        if len(self.lock_queue) == 0:
            return 0

        remaining_balls_to_release = balls_to_release

        self.log.debug("Releasing up to %s balls from lock", balls_to_release)
        balls_released = 0
        while len(self.lock_queue) > 0:
            device, balls_locked = self.lock_queue.pop()
            balls = balls_locked
            balls_in_device = device.balls
            if balls > balls_in_device:
                balls = balls_in_device

            if balls > remaining_balls_to_release:
                self.lock_queue.append((device, balls_locked - remaining_balls_to_release))
                balls = remaining_balls_to_release

            device.eject(balls=balls)
            balls_released += balls
            remaining_balls_to_release -= balls
            if remaining_balls_to_release <= 0:
                break

        if balls_released > 0:
            self.machine.events.post('ball_lock_' + self.name + '_balls_released',
                                     balls_released=balls_released)

        self.balls_locked -= balls_released
        return balls_released
Release all balls and return the actual amount of balls released.
dataset/ETHPy150Open missionpinball/mpf/mpf/devices/ball_lock.py/BallLock.release_balls