Django management call_command
Hello, I wrote a test management Command:
def start_daemon():
pidfile_rule = "/tmp/ihe_test.pid"
p = str(os.getpid())
file(pidfile_rule, 'w').write(p)
while True:
print "Hello"
sleep(10)
class Command(BaseCommand):
help = 'Starts or stops the daemons'
option_list = BaseCommand.option_list + (
make_option('--start',
action='store_true',
dest='status',
help='Start the daemons'),
make_option('--stop',
action='store_false',
dest='status',
default=False,
help='Stop the daemons'),
)
def handle(self, *args, **options):
status = options.get('status')
pidfile_rule = "/tmp/ihe_test.pid"
if status:
try:
start_daemon()
except Exception, e:
print e
else:
x = file(pidfile_rule, 'r').read()
os.kill(int(x), signal.SIGKILL)
Now what I want to accomplish:
In a form if a boolean field is True then execute (start) the daemon. If the boolean field is toggled False the daemon should be stopped. However the problem is:
wagnerf+ 5882 0.3 0.1 108892 21388 pts/3 S+ 17:32 0:00 /usr/bin/python2.7 manage.py runserver
wagnerf+ 5883 51.5 0.4 580376 52292 pts/3 Rl+ 17:32 0:35 /usr/bin/python2.7 manage.py runserve
One is the normal runserver and one is the daemon. Obviously I can't use the site anymore. How exactly must it be coded so that the managment call is a seperate process?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home