Skip to content

Instantly share code, notes, and snippets.

@1st1
Created September 8, 2015 16:05
Show Gist options
  • Select an option

  • Save 1st1/90f052171f062097d1bc to your computer and use it in GitHub Desktop.

Select an option

Save 1st1/90f052171f062097d1bc to your computer and use it in GitHub Desktop.
a quick example of new async/await in python 3.5
import asyncio
async def http_get(domain):
reader, writer = await asyncio.open_connection(domain, 80)
writer.write(b'\r\n'.join([
b'GET / HTTP/1.1',
b'Host: %b' % domain.encode('latin-1'),
b'Connection: close',
b'', b''
]))
async for line in reader:
print('>>>', line)
writer.close()
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(http_get('example.com'))
finally:
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment