1

Assume the following code:

import asyncio
import time

async def say_after():
    for i in range(10):
        await asyncio.sleep(1)
        print("first function")
async def say_after2():
    for i in range(10):
        await asyncio.sleep(1)
        print("second function")

async def main():
    await say_after()
    await say_after2()
asyncio.run(main())

It would first print "first function" 10 times and after function say_after is finished then it would print "second function" 10 times. now i want to run both functions at the same time like 2 threads (like parallel) with asycio not sequential executing. how do i do it?

AMIR
  • 99
  • 6
  • 4
    Possible duplicate of [Combine awaitables like Promise.all](https://stackoverflow.com/questions/34377319/combine-awaitables-like-promise-all) – Fine Feb 13 '19 at 15:57
  • What Python version is this code running on? In Python 3.6 `asyncio` has no `run` attribute. – holdenweb Feb 13 '19 at 16:15
  • it's 3.7. `.run` is new. no matter if you have any idea in 3.6 would be good as well – AMIR Feb 13 '19 at 16:20
  • https://docs.python.org/3/library/asyncio-task.html#asyncio.gather – balki Feb 13 '19 at 22:34
  • https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task – balki Feb 13 '19 at 22:38

0 Answers0