<jupyter_start><jupyter_text>Generators<jupyter_code>def numberGenerator(n):
     number = yield
     while number < n:
         number = yield number 
         number += 1

g = numberGenerator(10)    # Create our generator
next(g)                    # 
print(g.send(5))
next(g.send(10))
def bottom():
    # Returning the yield lets the value
    # that goes up the call stack
    # to come right back down.
    return (yield 42)

def middle():
    return (yield from bottom())

def top():
    return (yield from middle())

# Get the generator.
gen = top()
value = next(gen)
print(value)  # Prints '42'.
try:
    value = gen.send(value * 2)
except StopIteration as exc:
    value = exc.value
print(value)  # Prints '84'.<jupyter_output><empty_output><jupyter_text>async.io<jupyter_code>import asyncio

# Borrowed from http://curio.readthedocs.org/en/latest/tutorial.html.
@asyncio.coroutine
def countdown(number, n):
    while n > 0:
        print('T-minus', n, '({})'.format(number))
        yield from asyncio.sleep(1)
        n -= 1

loop = asyncio.get_event_loop()
tasks = [
    asyncio.ensure_future(countdown("A", 2)),
    asyncio.ensure_future(countdown("B", 3))]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()<jupyter_output><empty_output><jupyter_text>Not using async<jupyter_code>import time
# Borrowed from http://curio.readthedocs.org/en/latest/tutorial.html.
def countdown(number, n):
    while n > 0:
        print('T-minus', n, '({})'.format(number))
        yield time.sleep(1)
        n -= 1

for item in countdown("A", 2):
    continue
for item in countdown("B", 3):
    continue<jupyter_output><empty_output><jupyter_text>Async / await<jupyter_code>async def countdown(number, n):
    while n > 0:
        print('T-minus', n, '({})'.format(number))
        await asyncio.sleep(1)
        n -= 1
loop = asyncio.get_event_loop()
tasks = [
    asyncio.ensure_future(countdown("A", 2)),
    asyncio.ensure_future(countdown("B", 3))]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14516129032258066, 'fraction_numerical': 0.013685239491691105, 'mean_word_length': 3.5896860986547083, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '295408', 'license': 'MIT', 'n_tokens_mistral': 748, 'n_tokens_neox': 720, 'n_words': 159, 'path': '2020-07-26-python-async/async.ipynb', 'repo_name': 'Cheukting/python02hero', 'size': '2046'}