Question

I have a Python script that recursively sends data to a central server. The router will go to sleep until there's new data queued up to be transmitted. The wake up process takes about 20 Seconds or so thus I attempted to establish my connection as follows:

TIMEOUT = 100
def connect():
    return HTTPConnection(HOST, timeout=TIMEOUT)

connection = connect()

Now, I'd expect the function HTTPConnection() to return only once the timeout has expired which isn't what it's doing. My function returns after 3 or so seconds and gives me a connection error. Why is that? Do I need to write my own timeout loop?

Thank you, Ron

Was it helpful?

Solution

Well, the way I ended up fixing my problem is, in order to wake up the router, I send a ping with a very long timeout to 8.8.8.8 which will wake up the router and get a reply

def wakeup():
    subprocess.Popen(["/bin/ping", "-c2", "-w"+str(WAKETIME), PINGHOST], stdout=subprocess.PIPE).stdout.read()

And I just call this function before i do any other http requests so I don't have to bother with increasing the HTTP timeout at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top