0

i have a code to run a timer thread and its doing a job every x seconds and its has no problem

import threading
import datetime

def starThread():
    t = threading.Timer(0, Do_Analysis())
    t.start()

def Do_Analysis(): 
    #define  threading.Timer to do the job every x secound
    t=threading.Timer(1, Do_Analysis).start()
    print('datetime is : ',datetime.datetime.now())
    print(threading.active_count)

starThread()

i need to terminate the thread at some point and i dont know how to do it can anyone please guide me

1
  • 1
    You can cancel a waiting timer via the threading.Timer.cancel() method. Commented Jul 24, 2018 at 10:55

1 Answer 1

1

Do something like this:

t=threading.Timer(1, Do_Analysis)
t.start()
if True:
    t.cancel()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.