async def hello():
print('hello')
await asyncio.sleep(10)
async def world():
while 1:
try:
await asyncio.wait_for(hello(), timeout=0.1)
except:
print('world')
asyncio.run(world())
import asyncio
async def hello():
while True:
await asyncio.sleep(0.2)
print('hello')
async def world():
while True:
await asyncio.sleep(0.8)
print('world')
async def asynchronous():
tasks = [asyncio.ensure_future(hello()), asyncio.ensure_future(world())]
await asyncio.wait(tasks)
loop = asyncio.get_event_loop()
loop.run_until_complete(asynchronous())