2

I have an API handler function like this:

def handler():
    t = Thread(func, args=(args,))
    t.start()
    return {
       'status': 200,
       'data': 'Triggered data collection'
    }

It calls the func function which does some third party API calls and waits for its data. Something like this:

def func():
    resp, content = requests.get(BLABLABLABLA)
    return { 'status': 200, 'resp': content }

I have a cancel data collection functionality, which should be able to stop the thread execution of func(). The problem is when I kill the PID of func(), it waits for it to complete and then gets destroyed. Which can be very long time. Is there any way I can stop the thread right away or the process can kill the thread right away(I read that it is not a good idea but still :|)? BTW, due to some constraints I can't switch to multiprocessing.

Pratik
  • 1,351
  • 1
  • 20
  • 37

0 Answers0