async python
import asyncio
async def main():
print('Hello ...')
await asyncio.sleep(1)
print('... World!')
# Python 3.7+
asyncio.run(main())
# output
"""
Hello ...
...World!
"""
# with a 1 second wait time after Hello ...
async python
import asyncio
async def main():
print('Hello ...')
await asyncio.sleep(1)
print('... World!')
# Python 3.7+
asyncio.run(main())
# output
"""
Hello ...
...World!
"""
# with a 1 second wait time after Hello ...
python async await
import asyncio
async def print_B(): #Simple async def
print("B")
async def main_def():
print("A")
await asyncio.gather(print_B())
print("C")
asyncio.run(main_def())
# The function you wait for must include async
# The function you use await must include async
# The function you use await must run by asyncio.run(THE_FUNC())
asyncio sleep
#will sleep the current corutien for set numner of seconds
import asyncio
await asyncio.sleep(1)
python async await
import asyncio
from PIL import Image
import urllib.request as urllib2
async def getPic(): #Proof of async def
pic = Image.open(urllib2.urlopen("https://c.files.bbci.co.uk/E9DF/production/_96317895_gettyimages-164067218.jpg"))
return pic
async def main_def():
print("A")
print("Must await before get pic0...")
pic0 = await asyncio.gather(getPic())
print(pic0)
asyncio.run(main_def())
async, await, python
async def get_chat_id(name):
await asyncio.sleep(3)
return "chat-%s" % name
async def main():
id_coroutine = get_chat_id("django")
result = await id_coroutine
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us