Код: Выделить всё
import asyncio
async def f(duration: int) -> None:
await asyncio.sleep(duration)
async def main():
condition = False
task = asyncio.create_task(f(10))
await task
condition = bool(some_random_bool)
"""^^^this is supposed to be set
somewhere within the ten seconds;
in my case it should be a change
of a telegram user's state"""
if condition:
task.cancel()
if __name__ == "__main__":
asyncio.run(main())
Поэтому мне интересно, есть ли на самом деле способ остановить выполнение задачи вокруг сопрограммы на полпути.
Подробнее здесь: https://stackoverflow.com/questions/791 ... dom-moment
Мобильная версия