I have a Python program which sends several (about 5-6) long poll requests in parallel using different threads for each poll via requests package. And I realized that some of my threads sometimes just freeze. When this happens, the server I am sending the request does not receive the request. Also I set a timeout on the request and it does not work.
try:
print("This line prints")
response = requests.head(poll_request_url, timeout=180)
print("This line does not print when freeze occurs")
except ReadTimeout:
print("Request exception.")
except RequestException as e:
print("Request exception.")
except Exception:
print("Unknown exception.")
print("This line does not print either when freeze occurs.")
I am doing this on Raspberry Pi 2 hardware with Raspbian OS.
I used this same program without a problem when I was using Python 2.7. Recently I switched to Python 3.5. I tested using both requests versions with 2.8.1 and 2.9.1.
This problem does not occur very frequently but happens 2-3 times per day on different threads.
What might be the problem? How can I debug this?
Edit: The problem is solved by updating the Linux kernel.