Код: Выделить всё
import asyncio
import contextlib
import os
async def my_coroutine():
with open(os.devnull, 'w') as f, contextlib.redirect_stdout(f):
print("This will not be printed")
await asyncio.sleep(1)
print("This will be printed")
async def my_coroutine2():
print("This will be printed from 2")
await asyncio.sleep(1)
async def main():
await asyncio.gather(
my_coroutine(),
my_coroutine2()
)
asyncio.run(main())
Код: Выделить всё
This will be printed
Код: Выделить всё
This will be printed from 2
This will be printed
Подробнее здесь: https://stackoverflow.com/questions/792 ... -in-python