Creates a separate thread of execution (i.e. sends an email to the developer) in Flask Python?

I am running a webapp flash drive working for uwsgi (2 processes). Part of my code includes checking for a remote resource if it has been modified ( If-Modified-Since) and updated the local instance of this resource on the web server if it has changed.

This update also sends me an diff email. I am concerned that this takes a lot of time, as a result of which user timeout requests are sent via email.

Is the Python thread library the right way to solve this problem? (create a stream and send an email there?) Will it even interfere with uwsgi processes?

Thanks for the help!

(on the side of the note: I'm also a little worried that 2 uwsgi processes encounter errors if they both try to update the resource in the local copy ... I wonder if the blocking lock of the streaming module is correct, look at this problem?)

EDIT: To clarify, my main problem is that the email task is part of the code execution. This takes a lot of time and starts before the call return_template, therefore, holding the answer to the user. Is the Python thread library the right way to solve this problem given the Flask / uwsgi environment?

+5
source share
2 answers

uWSGI. , @timer :

from uwsgidecorators import *

#this will execute the_task() every 30 seconds in the spooler
@timer(30, target='spooler')
def the_task(signum)
    do_the_long_task()
+6

All Articles