[Flask] Outputting the results of Python commands to terminal like interface?

Unai Rodriguez unai at sysbible.org
Thu Oct 10 01:51:21 EDT 2019


Hi Simon,

I think one key aspect here is how long it takes for these commands to run. If they are quick (let's say a couple of seconds or less) you could run them synchronously and simply return the output straight to the UI that would be doing AJAX calls.

If the commands take some time you might need to make then asynchronously and perhaps use something like Celery to decouple the execution of the command itself with the invocation from the UI. In this case the result could be placed on the database or on some sort of temporary (redis?) storage. I'd imagine the UI requesting the execution of the command via AJAX and perhaps every couple seconds request again to see if the command completed to display the results. 

I'd also explore websockets since they will let your UI place a request and once the server is done, reply back (without having to poll every few seconds).

-- unai

On Thu, Oct 10, 2019, at 1:46 AM, Simon Connah wrote:
> I've been thinking of a new website I want to build. It will be my first 
> proper Flask website as all my previous websites have used Django. I 
> want to use the freedom that Flask has to output the results of 
> subprocesses on a website when calling code from the Python subprocess 
> module.
> 
> I'm somewhat confused about how to do this. I know there are various 
> JavaScript terminal emulators around which youcan use that allow proper 
> command input and output but since all of my commands will be 
> pre-written Python scripts it seems to be somewhat overkill.
> 
> Should I just take the results of the subprocess commands, save them to 
> the database and then on page refresh (either trough F5 or via 
> JavaScript) it will show the results of the command(s)?
> 
> I could then clean up the output and save it again to the database and 
> get rid of most of the superfluous data that isn't needed to store long 
> term. Another option since I am using PostgreSQL is to save the data as 
> JSON and just leave it like that for future recall.
> 
> Any hints and tips on what I should be doing?
> 
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>


More information about the Flask mailing list