bharadwaj-raju / WeatherDesk

MOVED: https://gitlab.com/bharadwaj-raju/WeatherDesk
https://gitlab.com/bharadwaj-raju/WeatherDesk
GNU General Public License v3.0
217 stars 31 forks source link

Not working after suspend/resume #25

Closed larskotthoff closed 8 years ago

larskotthoff commented 8 years ago

After I suspend and resume my laptop, WeatherDesk stops working. I get the following error on the first run after resume:

[Main loop]
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1240, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1083, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1079, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 911, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 854, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 1229, in connect
    super().connect()
  File "/usr/lib/python3.5/http/client.py", line 826, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "WeatherDesk/WeatherDesk.py", line 367, in <module>
    weather_json = json.loads(urlopen(weather_json_url).read().decode('utf-8'))
  File "/usr/lib/python3.5/urllib/request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 465, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 483, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 443, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1283, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib/python3.5/urllib/request.py", line 1242, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

I'm running Python 3.5.1 on Arch Linux.

bharadwaj-raju commented 8 years ago

Does it stop? Or keep running?

You can verify this by running pgrep python3 and then ps -fp [number] for each of the numbers pgrep returns.

If it stops, all we might have to do is also catch socket errors in the main loop's try .. except SomeException part.

bharadwaj-raju commented 8 years ago

Is your network connection temporarily down during the first few seconds after resume?

larskotthoff commented 8 years ago

It keeps running (and I get the same error again after the sleep interval). The network connection is indeed down for the first few seconds, but back by the time WeatherDesk runs (and as I've said it runs again afterwards with the same error when the network is definitely working).

bharadwaj-raju commented 8 years ago

Ah. This is a bug in Linux glibc. And the lead dev Ulrich Drepper didn't seem to care much:

That's what res_init() is for, call it.

This requires an ugly hack (loading libc.so and calling __res_init()), but it's all we can do till glibc fixes things.

Fix commited. Please test.

bharadwaj-raju commented 8 years ago

This causes it to fail the first run after suspend/resume, but works after that.

larskotthoff commented 8 years ago

Works fine, thanks! I can't test connecting to a different network after resume now, but will report back if that still causes trouble.

larskotthoff commented 8 years ago

Sorry, I'm getting the exact same error now after resuming on a different network.

bharadwaj-raju commented 8 years ago

Did you see my note? It says it will fail the first run after resume, but works after that.

What if you kill and restart the process?

Also, you mean if you just suspend/resume, it works, but if you suspend, then resume in a different network, it doesn't?

larskotthoff commented 8 years ago

This was resuming on a different network. I've tried it again and now it works after the one fail. Not sure what happened before -- I guess the wireless disconnected just when the script ran for a second? Anyway, it's working now. Sorry for the noise!