Skip to content

Observer-task running continuesly - best practice? #138

Answered by Miksus
thp44 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

Hmm, it indeed seems I have forgotten to mention about the permanent_task:

@app.task(permanent_task=True, on_startup=True, execution="async")
async def do_constantly():
    while True:
        ...
        await asyncio.sleep(0)

There are a couple of reasons to use this. Without it, the task risks being timeout. If you put infinite as the timeout, there is a problem in the shutdown: the scheduler waits for the task to finish by default (which will never happen). This attribute signals to the scheduler that the task should never timeout but it should not wait it to finish when the scheduler shuts down.

You can use any execution with the task except main as then the task blocks everythin…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@thp44
Comment options

@Miksus
Comment options

Answer selected by thp44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants