I have the two functions below and I want them to run in parallel just like we use go routines in Go. Currently these do not run in parallel.
Please note that there is no async code in each of the functions, and I need to use returned data from both functions for later use.
Code:
import asyncio
async def func1(i: int) -> int:
print("Initiated func1")
while i <= 100000000:
i += 1
print("Finished func1")
return 100
async def func2() -> (str, int):
print("Initiated func2")
return "hello world", 200
async def main():
res = await asyncio.gather(*(func1(10), func2()))
return res
if __name__ == "__main__":
data1, data2 = asyncio.run(main())
print(f"func1: {data1}, func2: {data2}")
Actual output:
Initiated func1
Finished func1
Initiated func2
func1: 100, func2: ('hello world', 200)
Expected output:
Initiated func1
Initiated func2
Finished func1
func1: 100, func2: ('hello world', 200)