[Django]-Python:running command in the background

4👍

You can use http://celeryproject.org/, it works like a charm, it has nice Django integration, it’s very well documented and used by many.

👤skrat

1👍

May be the below program helps you.

background.py

import subprocess

def background_execute(command):
    # launching the command
    p1 = subprocess.Popen(command,shell=True,stdout=True)
    p1.wait()
    print "Wait over, child exits"
    <Here you can add code to send mail>

Usage:

background_execute(["python sleep.py"])

sleep.py

import time

print "I am in sleep script, and will sleep for 10 sec"
time.sleep(10)
print "exit from child"

Leave a comment