Skip to content

Instantly share code, notes, and snippets.

@rmsaitam
Created August 15, 2025 18:16
Show Gist options
  • Select an option

  • Save rmsaitam/d3644d999ed1fb2c229ae6d087c16949 to your computer and use it in GitHub Desktop.

Select an option

Save rmsaitam/d3644d999ed1fb2c229ae6d087c16949 to your computer and use it in GitHub Desktop.
Exemplo de programação assíncrona no Python
import asyncio
import aiohttp
async def fetch(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
print(f"Baixando {url}...")
html = await response.text()
print(f"Concluído: {url} ({len(html)} caracteres)")
return html
async def main():
urls = [
"https://example.com",
"https://httpbin.org/get",
"https://python.org"
]
# Executa todas as requisições ao mesmo tempo
resultados = await asyncio.gather(*(fetch(url) for url in urls))
print("\nDownloads finalizados!")
# Executar o programa
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment