Skip to content

Instantly share code, notes, and snippets.

@NeuronQ
Created February 5, 2019 23:57
Embed
What would you like to do?
# async_scrape.py (requires Python 3.7+)
import asyncio, random, time
async def fetch_url(url):
print(f"~ executing fetch_url({url})")
t = time.perf_counter()
await asyncio.sleep(random.randint(1, 5))
print(f"time of fetch_url({url}): {time.perf_counter() - t:.2f}s")
return f"<em>fake</em> page html for {url}"
async def analyze_sentiment(html):
print(f"~ executing analyze_sentiment('{html}')")
t = time.perf_counter()
await asyncio.sleep(random.randint(1, 5))
r = {"positive": random.uniform(0, 1)}
print(f"time of analyze_sentiment('{html}'): {time.perf_counter() - t:.2f}s")
return r
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment