Here is how I am making an HTTP Post request from a worker thread.
while some_conditon:
# get data from the queue.
resp = requests.post('www.test.com', data=mydata, timeout=30)
In the above scenario, when I want to exit the application, and say the requests.post method has already executed, I will have to wait for 30 sec in the worst case. Is there a way to abort the request and exit immediately?
I know I can make the worker thread as a daemon thread and simply exit the main thread but that leads to abrupt killing of the worker thread which leads to unexpected exception.
One way to handle this would be to use futures and periodically check if the future is done, something similar to this How do you kill Futures once they have started? but I wanted to know if there is any other way to do it.