Starting an http request, but dropping out if no response after a certain time
Posted
by nbv4
on Stack Overflow
See other posts from Stack Overflow
or by nbv4
Published on 2010-05-09T16:12:47Z
Indexed on
2010/05/09
16:18 UTC
Read the original article
Hit count: 191
python
|code-timing
I'm trying to write a python script that does the following from within a minutely cronjob:
- tries to execute a url
- after 10 seconds if there is no response yet, abandon the response and immediately issue a command via os.system to restart the webserver.
The problem is that when my server crashes, it doesn't return a response at all. If I were to just have my script time the response, the script will go on for 10 minutes or more. I want it to issue the restart immediately once it detects a slow response. I know such a script could be written in probably less than 5 mines of code, but I have no idea how to go about it.
© Stack Overflow or respective owner