A
A
Ahos2019-08-18 15:21:03
Python
Ahos, 2019-08-18 15:21:03

Is it possible to run a coroutine without blocking execution (asyncio)?

I apologize right away - I'm new to programming, so the question may be stupid.
Is it possible to run a coroutine/task without blocking further code execution?
For example:

import asyncio

condition = False


async def do_something_important():
    #тут происходит что-то важное


async def main():
    while True:
        #здесь что-то происходит, что-то считается и в какой-то момент
        #condition меняется на True

        if condition:
            #тут запускается do_something_important():
            #и оставляет его работать "в фоне" не дожидаясь результатов

        #здесь продолжается работа


asyncio.run(main())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-08-18
@Ahos

asyncio.Task(do_something_important())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question