How to call a python function repeatedly by one cmd call??

I want to call my python function repeatedly every 1 second by just one call from the python cmd window (output log window).
I tried to use a
for i in range(5):
actor.setLocation(currentLocation+i)
time.sleep(1)

but I found that the editor shows the final result after 5 seconds!!(that is, the editor got freeze until 5 seconds passed)!!! but I wanted to move the actor 1 by 1 every 1 second. So I needed to call(enter) the function again and again manually instead of using the for-loop…

Please help me!!