I am building a flask application that prompts a user for his/her email and an input file. When the user enters them both, I run a script on this input file. Now this script takes a good amount of time to execute. I want to mail the result of this script evaluation to the user. However my page freezes for as long as the script is executing. I want my user to be able to go to another page displaying that his response has been submitted for processing and he shall be mailed it in a while, rather than him being stuck on the page for as long as the script executes. Any leads would be appreciated
I ultimately used the Threading module
made available in python, the implementation was quite simple, to generate a new thread that would take care of rendering the redirected page and the main thread would execute my script. If anybody needs it,
class Mythread(threading.Thread):
def __init__(self, params):
threading.Thread.__init__(self)
self.h = i
self.params = params
def run(self):
time.sleep(1)
# do expensive work, your time taking script
and i would call it as:
thread1 = Mythread(1, params)
thread1.start()
return open('redirectpage.html')
This way my page wouldn't hang as long as the script runs
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments