Can drivetrain driving velocity be set in a while loop?

I am trying to make something that smoothly increases the drivetrain velocity as it drives for smooth acceleration. The following code I made and tested in VexVR (Didn’t have access to the bot at the time) but once I tested it on the bot itself it seemed not to be setting the velocity during the while loop. Is there something that is preventing it from being set very often?

#-------------------
def driveFor(dire, dist, units, startVel, endVel, inc):
    drive.set_drive_velocity(startVel, PERCENT)
    drive.drive_for(dire, dist, units, wait=False)
    vel = startVel
    while drive.is_moving():
        vel = min((vel+inc), endVel)
        drive.set_drive_velocity(vel)
        wait(100, MSEC)
#-------------------

I don’t think you can set the velocity during a drive function like drive_for. Instead, you need to tell the motors to spin forever, then update the speed in a loop, then end the loop and stop the motors once you reach the target. Here’s some pseudo code:

startMotors()

while (distanceTraveled < targetDistance): 
    setMotorSpeed(whateverYouWant)
    wait(20, msec)

stopMotors()

Of course this is very simplified, but should help you get the idea.

Also this appears to be a duplicate of this thread, please don’t make the same thread twice