Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

do i have to remove the workers in flask-dramatiq?

the docs only shows how to start but it does not say anything about stopping the workers? is it necessary? if so, how?

I cant seem to find anything to close it
docs: https://flask-dramatiq.readthedocs.io/en/latest/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In Flask-Dramatiq, you don’t necessarily need to remove or stop the workers manually. When you start the workers using flask_dramatiq.Dramatiq, they will continue running until you stop the Flask application.

You can stop the Flask application in a number of ways, such as using the Ctrl + C command or by programmatically stopping the Flask application using the app_context().push() method.

When the Flask application is stopped, the workers started by flask_dramatiq.Dramatiq will automatically be terminated.

If you want to programmatically stop the workers, you can use the dramatiq.broker.Broker.join() method. This method will block the current thread until all tasks have finished processing and all workers have exited:

from flask import Flask
import dramatiq
from flask_dramatiq import Dramatiq

app = Flask(__name__)
dramatiq_broker = dramatiq.get_broker()

dramatiq = Dramatiq(app)

dramatiq_broker.start()
dramatiq.flush_join()

dramatiq_broker.join()

In the code above, dramatiq_broker.start() starts the workers, and dramatiq_broker.join() stops the workers. The dramatiq.flush_join() method blocks the current thread until all tasks have been processed before calling dramatiq_broker.join().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading