Understanding asynchronous operations
Some of the operations in a web application can be time-consuming and make the overall application feel slow for the user, even though it's not actually slow. This decreases the user experience significantly. To deal with this, the simplest way to implement the asynchronous execution of operations is with the help of threads. In this recipe, we will implement it using the thread
and threading
libraries of Python. The threading
library is simply an interface over thread
; it provides more functionality and hides things that are normally not used by users.
Getting ready
We will use the application from the E-mail support for Flask applications recipe. Many of us will have noticed that while the e-mail is being sent, the application waits for the whole process to finish, which is actually unnecessary. E-mail sending can be easily done in the background, and our application can become available to the user instantaneously.
How to do it…
Doing an...