Skip to content

Instantly share code, notes, and snippets.

@srkama
Created December 19, 2018 09:57
Show Gist options
  • Save srkama/d0548197fdb2d0547ca7ff649aaed94f to your computer and use it in GitHub Desktop.
Save srkama/d0548197fdb2d0547ca7ff649aaed94f to your computer and use it in GitHub Desktop.
async url checker with aiohttp
import asyncio
import aiohttp
async def check_website(url_to_ping):
while True:
print("trying {0}".format(url_to_ping))
try:
async with aiohttp.ClientSession() as session:
async with session.get(url_to_ping) as response:
response = await response.text()
await asyncio.sleep(10)
except Exception as e:
print(e)
await asyncio.sleep(10)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
a = ["https://www.google.com", "https://www.ls.co.uk/"]
for url in a:
loop.create_task(check_website(url))
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment