I have been figuring on how to run a script on background, so that i can process an object without having the user to wait for the server to respond.
Views.py
import subprocess, sys
def allocate_request(request, event_id):
event = get_object_or_404(MeetingEvent, id=event_id)
subprocess.Popen([sys.executable, 'sorting.py', str(event_id)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return HttpResponse("Request Submitted.")
and in the same directory, Sorting.py
import sys
class Organize:
if len(sys.argv) <= 1:
event_id = int(sys.argv[1])
event_i = MeetingEvent.objects.get(id=event_id)
Problem is...
the script itself can't be run alone,
from .models import MeetingEvent
ModuleNotFoundError: No module named '__main__.models'; '__main__' is not a package
Would appreciate any help :)