To point you a little closer to what it sounds like you're wanting:
import threading
def poll_position(fobj, seconds=0.5):
"""Call once to repeatedly get statistics every N seconds."""
position = getMotorPosition()
# Do something with the position.
# Could store it in a (global) variable or log it to file.
print position
fobj.write(position + '\n')
# Set a timer to run this function again.
t = threading.Timer(seconds, poll_position, args=[fobj, seconds])
t.daemon = True
t.start()
def control_loop(positions, velocity):
"""Repeatedly moves the motor through a list of positions at a given velocity."""
while True:
for position in positions:
moveMotorToPosition(position, velocity)
if __name__ == '__main__':
# Start the position gathering thread.
poll_position()
# Define `position` and `velocity` as it relates to `moveMotorToPosition()`.
control_loop([first_position, second_position], velocity)