Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import treq
from twisted.internet.task import react
from twisted.internet.defer import ensureDeferred
urls = [
b"https://www.torproject.org",
b"https://meejah.ca",
]
async def main(reactor):
async for z in x():
print("Z: {}".format(z))
print("done")
async def x():
for url in urls:
result = await get(url)
print("yielding '{}'".format(result))
yield result
async def get(url):
resp = await treq.get(url)
data = await resp.content()
return data[:20]
if __name__ == '__main__':
react(
lambda r: ensureDeferred(main(r))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.