i3-weather
i3-weather copied to clipboard
Fix DNS timeout issue
So I think I finally figured out what causes the mysterious issue where the script hangs (and thus your i3 statusbar is frozen and you're late because your clock is wrong), even though we're using the timeout
parameter for requests.get()
. The issue is that in some situations, it's not the HTTP request that is timing out, but the DNS lookup. In particular, this happens when I am connected to my home network, but the modem is unable to connect to the internet. I noticed that running python weather.py <woeid>
without --wrap-i3-status
under such circumstances isn't even interruptible with SIGINT
.
It appears that someone else ran into this issue: https://github.com/kennethreitz/requests/issues/2347
Which was deemed as an issue with urllib3
: http://bugs.python.org/issue22889
Which does not have a clear resolution in terms of what clients of requests
should do, other than calling requests
from a separate thread.
@kalgynirae What are your thoughts on this? The Python issue above mentions working around this with asyncio
, with which I am not familiar.
This does sound like a probable cause of the issue. I will look into whether it would be easy to use asyncio
to do the request.