Forums

Subroutines Using Always-On Tasks = Tarpit?

I spent time reworking my code since threading is not supported (

(everything works great besides slow times, due to being in the tarpit

Threading should work Always-on tasks -- we only have constraints in the web apps. You'd be put in the tarpit if you used all your CPU daily quota. Check if you don't have something in your code that would consume CPU seconds fast, like an infinite loop without any sleeps, etc.

I appreciate the explanation. My issue is that I sort of do need an infinite loop, to handle pending tasks. Even when there are no pending or processing tasks in my database, I need a way to constantly check.

Just sleep and check in while True loop.

...if my code is sleeping and a new Task comes in then there will be latency. I have it give it more thought but I think I came up with a solution.
If it works I will post here.

Perhaps I will somehow trigger the subroutine loop only when a Task is created, that way its only running when there may be something to do. The issue is getting the subroutine loop to run on a different thread than the webapp creating the Task..

You may need nested loops, if I understand you correctly, sleepy one to save cpu and busy one inside when it's needed. Anyways, always-on tasks can only pull and can't be pushed for outside. You could also dynamically create tasks with an API. See https://help.pythonanywhere.com/pages/API/ but it takes a moment for always-on task to spin up.