1
I want a certain flow to continue even calling a async.sleep() in the code, I have the following code
import asyncio
async def funcao_1(name):
print("entrando no sono...")
await asyncio.sleep(3)
print("saindo do sono...")
async def main():
result = await asyncio.gather(funcao_1())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
print("rodando depois do run_until_complete")
Expected exit
entrando no sono...
rodando depois do run_until_complete
saindo do sono...
Return exit
entrando no sono...
saindo do sono...
rodando depois do run_until_complete
Python version
$ python3 --version
Python 3.6.7rc1
Is there any way to do this in Python?
there is another way without using the function
gather? type in my initial proposal to run an execution after therun_until_complete(main())orasyncio.run(main())– Davi Wesley
@Daviwesley Codes that will be executed concurrently should be marked as
async, so I created two separate functions and marked them withasync. If the code is not marked asasync, The Event loop has no way of controlling the execution and therefore has no way of being a competitor. If you don’t want to use Event loop for some reason, you’ll have to use threads directly, but I recommend using onlyasync, because the end result gets more expressive and simple than using threads directly.– Gabriel