Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2016 17:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import trollius as asyncio
from trollius import From
def factorial(name, number):
f = 1
for i in range(2, number + 1):
print("Task %s: Compute factorial(%d)..." % (name, i))
yield From(asyncio.sleep(1))
f *= i
print("Task %s completed! factorial(%d) is %d" % (name, number, f))
loop = asyncio.get_event_loop()
tasks = [
asyncio.async(factorial("A", 8)),
asyncio.async(factorial("B", 3)),
asyncio.async(factorial("C", 4))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment