Multi-threading with a simple timer?

David D daviddschool at gmail.com
Tue Jul 3 16:56:57 EDT 2018


I have some success with this.  I am not sure if this would work longer term, as in restarting it, but so far so good.  Any issue with this new code?

import time
from threading import Thread

th=Thread()
class Answer(Thread):
    def run(self):
        a=input("What is your answer:")
        if a=="yes":
            print("yes you got it")
            th.daemon=False
        else:
            print("no")

class myTimer(Thread):
    def run(self):
        print()

        for x in range(5):
            if th.daemon==True:
                print(x)
                time.sleep(1)
            else:
                break

th.daemon=True

Answer().start()
myTimer().start()


def finished():
    print("done")




More information about the Python-list mailing list