Is there anyway, without using threading, to get python to do the following

do for 5 seconds
do action
else
do something else

Here is example code:

from time import clock,sleep

duration=5
time_to_change=clock()+duration

while True: 
    if clock()<time_to_change:
        print('Action 1')
    else:
        print('Something else')
        
    sleep(0.1)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.