如何结束线程任务?

How to end the threading task?

如何结束线程任务?我的代码是这样的:

import threading

def printit():
    threading.Timer(5.0, printit).start()
    print('Hello!')
printit()

试试这个:

def printit(stop):
    thread  = threading.Timer(5.0, printit)
    thread.start()
    print('Hello!')
    x = 'your_stopping_condition'
    if x == 'your_stopping_condition':
        t.cancel()
printit()
import threading

def printit():
    thread  = threading.Timer(1.0, printit)
    thread.start()
    x = 'your_stopping_condition'
    if x == 'your_stopping_condition':
        thread.cancel()
    else:
        print('Hello!')
printit()