Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python yield async await thread function

import asyncio

async def createGenerator():
    mylist = range(3)
    for i in mylist:
        await asyncio.sleep(1)
        yield i*i

async def start():
    async for i in createGenerator():
        print(i)

loop = asyncio.get_event_loop()

try:
    loop.run_until_complete(start())

except KeyboardInterrupt:
    loop.stop()
    pass
Comment

python yield async await

import asyncio


async def async_generator():
    for i in range(3):
        await asyncio.sleep(1)
        yield i*i


async def main():
    async for i in async_generator():
        print(i)


loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.run_until_complete(loop.shutdown_asyncgens())  # see: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.shutdown_asyncgens
    loop.close()
Comment

PREVIOUS NEXT
Code Example
Python :: django not configured pylint error fix 
Python :: loop through KeyedVectors 
Python :: find if string is substring of another 
Python :: How to convert string to uppercase, lowercase and how to swapcase in python 
Python :: design patterns in python free download 
Python :: python print list of keywords 
Python :: pandas assign multiple columns 
Python :: pyhton transpose without changing column and row names 
Python :: ValueError: minvalue must be less than or equal to maxvalue 
Python :: aws django create superuser 
Python :: qr code scanner on django 
Python :: json object type in python 
Python :: data structures in python 
Python :: Python - Common Conditional Statements 
Python :: Using iterable unpacking operator * 
Python :: how to use kite python 
Python :: upper method in python 
Python :: spotify meist gespielte lieder sehen 
Python :: internet spam 
Python :: datetime day deutsch python 
Python :: Add silence to the end of an MP3 python 
Python :: pyAesCrypt 
Python :: how to sum a column in csv python using list in python 
Python :: tf.data.Dataset select files with labels filter 
Python :: Reading from a file way02 
Python :: what to replace the rect pygame command 
Python :: adding new character in string python 
Python :: pypi cryptography 
Python :: bs4 check element type 
Python :: cv2 jupyter notebook matplotlib inverted colors fix 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =