Rasberry Pi Controlling Arduino - Reads "Ghost" Input - Doesn't Complete Logic Loop
What motor are you using? If it works straight from the 5v but not from a GPIO, it could be an issue of insufficient power.
As @StarCat4 mentioned, you also need to add a digitalRead inside your while loop if you want the motor to ever turn off.