global command
while True:
    data = read_sensors()
with command_lock:
    command = process(data)

def motor_thread():
    while True:
        while not command:
            time.sleep(0.01)
with command_lock:
    motor_do(command)
command = None
time.sleep(delay)
How to multithread/multiprocess just one instance of a particular function in Python?