Tag archive for: monitor

How to use threading.Condition to wait for several Flask-APScheduler one-off jobs to complete execution in your Python 3 application

Previously, I discussed how to use Flask-APScheduler in your Python 3 Flask application to run multiple tasks in parallel, from a single HTTP request.

When we run jobs as discussed in that post, jobs are ran once by the underlying ApScheduler instance. In addition, our Flask endpoint return the HTTP response back to the HTTP client as soon as the jobs are scheduled.

If we do not want the HTTP client to know the outcome of the jobs within that HTTP call, then we are good. But what if we want to include any errors that the jobs encounter in the same HTTP response?

In such a situation, we will need a mechanism to wait for the one-off jobs to complete execution before returning that response.

Given that in mind, this post shows how we can use threading.Condition to wait for several Flask-APScheduler one-off jobs to complete execution.