thread that represents the initial thread of control and which is not daemonic in older codet setdaemon(flagand isdaemon(are used to manipulate this value here is an example that shows how to create and launch function (or other callableas threadimport threading import time def clock(interval)while trueprint("the time is %stime ctime()time sleep(intervalt threading thread(target=clockargs=( ,) daemon true start(here is an example that shows how to define the same thread as classimport threading import time class clockthread(threading thread)def _init_ (self,interval)threading thread _init_ (selfself daemon true self interval interval def run(self)while trueprint("the time is %stime ctime()time sleep(self intervalt clockprocess( start(if you define thread as class and define your own _init_ (methodit is critically important to call the base class constructor thread _init_ (as shown if you forget thisyou will get nasty error other than run()it is an error to override any of the other methods already defined for thread the setting of the daemon attribute in these examples is common feature of threads that will run forever in the background normallypython waits for all threads to terminate before the interpreter exits howeverfor nonterminating background tasksthis behavior is often undesirable setting the daemon flag makes the interpreter quit immediately after the main program exits in this casethe daemonic threads are simply destroyed timer objects timer object is used to execute function at some later time timer(intervalfunc [args [kwargs]]creates timer object that runs the function func after interval seconds have elapsed args and kwargs provide the arguments and keyword arguments passed to func the timer does not start until the start(method is called lib fl ff