Skip to content
Advertisement

asyncio.gather not executing tasks when caller function requests input from STDIN?

In the following contrived example I am attempting to get input from STDIN and execute a list of coroutine tasks concurrently using asyncio.gather based on the input from STDIN.:

JavaScript

However when executing the above code the output does not contain the desired output when the corresponding option is entered.

Input ‘1’ from STDIN should print to STDOUT:

JavaScript

Input ‘2’ from STDIN should print to STDOUT:

JavaScript

When entering either ‘1’ or ‘two’ there’s no output. Why aren’t any of the tasks being executed by asyncio.gather?

Advertisement

Answer

You need to await the asyncio, and you need to pass it multiple arguments, not a list.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement