Skip to content

Instantly share code, notes, and snippets.

@abulka
Created March 1, 2019 06:14
Show Gist options
  • Save abulka/e27352615d0ba5bb36811278d801601f to your computer and use it in GitHub Desktop.
Save abulka/e27352615d0ba5bb36811278d801601f to your computer and use it in GitHub Desktop.
Check for latest app version asynchronously inside wxPython app
import asyncio
import aiohttp
from async_lru import alru_cache
@alru_cache(maxsize=32)
async def url_to_data(url):
timeout = aiohttp.ClientTimeout(total=60)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url) as response:
return await response.read(), response.status
async def check_for_updates(self):
await asyncio.sleep(15)
status_code = 0
try:
data, status_code = await url_to_data(VERSION_CHECK_URL_TRACKED)
response_text = data.decode('utf-8')
info = eval(response_text)
except asyncio.TimeoutError as e: # there is no string repr of this exception
print("time out getting latest version info")
except aiohttp.client_exceptions.ClientConnectorError as e:
print("connection error (no internet?) getting latest version info")
else:
print(f"checked url for updates: {url}")
if status_code == 200:
self._update_alert(info, alert_even_if_running_latest=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment