0

I'm an intern in a laboratory in my college that works with air quality, and they want me to improve their website that runs one of the programs that air quality researchers use (I think that the program is written in RUST). The way it works right now is that the user uploads some necessary files to the webapp (that is written in Django btw) and then the webapp calls this program, that runs on the server with the uploaded files. The problem is that if the user leave or refresh the page, the background program will stop. I have never dealt with this concept of running other executables in the background of the server, so I'm having some problems understanding it all. I came across the "Celery" package for python, but it seems really hard to implement and I was wondering if there was any other ways of doing this.

lumnus
  • 5
  • 1

1 Answers1

0

You can do it with subprocess

template.html

<form action="{% url 'run_sh' %}" method="POST">
    {% csrf_token %}
    <button type="submit">Call</button>
</form>

urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('run-sh/', views.index, name='run_sh')
]

views.py

import subprocess

def index(request):
    if request.POST:
        subprocess.call('/home/user/test.sh') 

    return render(request,'index.html',{})

test.sh

#!/bin/sh
echo 'hello'

Based on answers to this question

periwinkle
  • 386
  • 3
  • 9