Skip to content

Instantly share code, notes, and snippets.

@ottolotto
ottolotto / asyncio_prints.py
Created January 29, 2016 14:09 — forked from hjwp/asyncio_prints.py
an illustration of the difference between "yield from" and "create_task" in asyncio
import asyncio
import random
@asyncio.coroutine
def print_whenever(identifier):
"""a little function that prints at random intervals"""
while True:
yield from asyncio.sleep(random.choice([0.5, 1, 1.3]))
print('hi from', identifier)
@ottolotto
ottolotto / asyncio-tornado.py
Created January 27, 2016 14:24 — forked from ecryth/asyncio-tornado.py
Running Tornado on asyncio's event loop, including 'yield from' support in request handlers
import asyncio
import tornado.concurrent
import tornado.ioloop
import tornado.web
import tornado.platform.asyncio
import tornado.httpclient
class ReqHandler(tornado.web.RequestHandler):
async def get(self):