V
V
Viktor Shcherba2014-04-21 18:02:44
Python
Viktor Shcherba, 2014-04-21 18:02:44

How to run a python script through the web interface and return an execution response?

Good afternoon everyone.
Tell me how you can implement the following task:
There is a python script that solves a mathematical problem.
The initial data for the task is stored in the database from which it is planned to pull the data.
There will also be a Django web interface through which these initial data can be edited.
Right now I'm running the script from the terminal and giving it test data from csv files.
Based on the above, a few questions:
1) How to run a script with calculations on the server through a website?
2) How to implement a script response with an execution status so that it is possible to signal the user about the execution?
UPD: The problem of linear programming of large dimension is being solved, because of which the solution time can be large; or I can set the execution time myself.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
kfuntov, 2014-04-21
@aprex

1) There are many ways to run a server-side console script from a web-face, you need to look at specific circumstances, a couple offhand:
* Celery ( www.celeryproject.org/) - a fairly large infrastructure for executing tasks
* os.subprocess.call ( https:/ /docs.python.org/2/library/subprocess.html) - running commands from a python script
To choose from these two, you need to answer something like this:
* Is the crap being run - a python script that I can modify? (If not, then celery is not very convenient to screw, but there are other adequate solutions)
* Would it be bad if someone (or several people) quickly requested the execution of the crap being launched many times at the same time? (If yes, then subprocess is unlikely to fit, so some kind of queue manager is most likely needed) 2) Signaling
the completion of something can be varied (most likely you have seen all this in different systems):
all pages) - the user needs to refresh the page to see the status change.
* AJAX requests to the server that update the status displayed on the page automatically
* e-mail or sms
* push notification to the mobile application :)
If you decide, I can describe something in more detail (each option is considered in detail, unfortunately, extremely lazy ).

V
Valentin, 2014-04-21
@vvpoloskin

So if the script is in python, and django is used as a web interface, why not take the code in the script into a separate function, and in django processing, just import and call this function? Why be wise)

E
EvilX, 2014-04-21
@EvilX

Does the script run for a long time? Maybe the good old cgi is enough?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question