I have the following code which turns an outlet on/off every 3 seconds.
    start_time = time.time()
    counter  = 0
    agent = snmpy4.Agent("192.168.9.50")
    while True:
        if (counter % 2 == 0):
            agent.set("1.3.6.1.4.1.13742.6.4.1.2.1.2.1.1",1)
        else:
            agent.set("1.3.6.1.4.1.13742.6.4.1.2.1.2.1.1", 0)
        time.sleep(3- ((time.time()-start_time) % 3))
        counter = counter + 1
Is there a way I can have the loop terminate at any given point if something is entered, (space) for example... while letting the code above run in the mean time
 
    