Flask: Execute time taking python script and direct the user to another page

Apoorva Srivastava

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

Apoorva Srivastava

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Execute a Python script in Flask

From Dev

Unable to execute python web scraping script successfully after user submits a form on a website built with Flask from the second time onwards

From Dev

Sudo execute shell script is different behavior compared to direct user execute it

From Dev

Is it possible to execute a script that takes user input then execute another script

From Dev

Execute and create one python script from another

From Dev

Execute sudo Bash script as another user while being root

From Dev

Execute script relative to another user's home directory

From Dev

Direct a value to another page jquery?

From Java

Execute a bash command in a pod that runs a python script in another script in Kubernetes

From Dev

Execute another python script, then shut down current script

From Dev

Script to direct user info correctly

From Dev

Why is this MATLAB script taking so long to execute?

From Dev

Java program to execute a command taking a long time

From Dev

PL/SQL block taking lot of time to execute

From Dev

ServiceStack taking a long time to execute stored procedure

From Dev

MySQL taking too much time to execute

From Dev

Code is taking so much time to execute?

From Dev

Nested for loop taking long time to execute in R

From Dev

Execute as another user that is not root

From Dev

Execute script as a specific user

From Dev

Flask User Page with ID

From Dev

One Python script giving "user input" to another python script

From Dev

One Python script giving "user input" to another python script

From Dev

how a flask-python script calls another flask-python script

From Dev

Redirecing user to another page using javascript in less time

From Dev

Why is this script taking more time in python3 than python2?

From Dev

Readmore button taking user to top of the page

From Dev

WordPress categories are taking huge time in page load

From Dev

Taking time as user input in HHMM format

Related Related

  1. 1

    Execute a Python script in Flask

  2. 2

    Unable to execute python web scraping script successfully after user submits a form on a website built with Flask from the second time onwards

  3. 3

    Sudo execute shell script is different behavior compared to direct user execute it

  4. 4

    Is it possible to execute a script that takes user input then execute another script

  5. 5

    Execute and create one python script from another

  6. 6

    Execute sudo Bash script as another user while being root

  7. 7

    Execute script relative to another user's home directory

  8. 8

    Direct a value to another page jquery?

  9. 9

    Execute a bash command in a pod that runs a python script in another script in Kubernetes

  10. 10

    Execute another python script, then shut down current script

  11. 11

    Script to direct user info correctly

  12. 12

    Why is this MATLAB script taking so long to execute?

  13. 13

    Java program to execute a command taking a long time

  14. 14

    PL/SQL block taking lot of time to execute

  15. 15

    ServiceStack taking a long time to execute stored procedure

  16. 16

    MySQL taking too much time to execute

  17. 17

    Code is taking so much time to execute?

  18. 18

    Nested for loop taking long time to execute in R

  19. 19

    Execute as another user that is not root

  20. 20

    Execute script as a specific user

  21. 21

    Flask User Page with ID

  22. 22

    One Python script giving "user input" to another python script

  23. 23

    One Python script giving "user input" to another python script

  24. 24

    how a flask-python script calls another flask-python script

  25. 25

    Redirecing user to another page using javascript in less time

  26. 26

    Why is this script taking more time in python3 than python2?

  27. 27

    Readmore button taking user to top of the page

  28. 28

    WordPress categories are taking huge time in page load

  29. 29

    Taking time as user input in HHMM format

HotTag

Archive