[mar-2024] this work for me.
import asyncio
async def __main(num1: int, num2: int):
tasks = []
tasks.append(print1(num1))
tasks.append(print2(num2))
print('starting main()')
# Run the tasks concurrently
await asyncio.gather(*tasks)
# above could be simpler
task1 = asyncio.create_task(print1)
task2 = asyncio.create_task(print2)
await task1
await task2
And invoke the async function like this:
import threading
def run():
# new thread
thread = threading.Thread()
thread.target = asyncio.run(__main(1, 2))
thread.run() # or thread.start()
there's no need to pass args. I suppose within the synchronous context asyncio.run runs normally as synchronous. The Async behavioir is implicit in the line where the await ... declaration is specified.