Book Image

Learning Flask Framework

Book Image

Learning Flask Framework

Overview of this book

Table of Contents (17 chapters)
Learning Flask Framework
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Asynchronous tasks with Celery


Celery is a library that allows you to run asynchronous tasks within Python. This is especially helpful in Python as Python runs single threaded and you may find that you have a long-running task that you wish to either start and discard; or you may wish to give the user of your website some feedback on the progress of the said task.

One such example is e-mail. A user may request an e-mail to be sent, for example a password reset request, and you don't want them waiting for the page to load while the e-mail is generated and sent. We can set this up as a start and discard operation and let the user know that the request is being dealt with.

The way Celery is able to escape the single-threaded environment of Python is that we have to run a Celery broker instance separately which; this creates what Celery calls workers that do the actual work. Your Flask app and the workers then communicate with each other via the messaging broker.

So obviously, we need to install...