I use Django develpment server to start a daemon, it performs all the commands from the views.py, but web page hangs. Daemon is starting normally but web page hanging needs to be fixed. I work under Red Hat Enterprise Linux 6.3.
To make sure that it's not my or my daemon mistake I performed the following test:
1) I created new Django project "djtesting", where created one views.py file with the following code (it starts httpd daemon):
from django.http import HttpResponse
import subprocess
def hello(request):
res = subprocess.call("/usr/sbin/httpd")
return HttpResponse("Testing.")
2) Added this function to urls.py:
from django.conf.urls.defaults import patterns, include, url
from djtesting.views import hello
urlpatterns = patterns('',
('^hello/$', hello),
)
3) Then I started web server with "python manage.py runserver 192.168.1.226:8000" and open web page with "http://192.168.1.226:8000/hello/" in browser. It shows "Testing" message and then hangs (starts loading and hangs on this) although daemon started normally. But if to stop the daemon with "/etc/init.d/httpd stop" the web page stops loading. It seems that the server is waiting until the daemon finish working, but I need just to start it without waiting until it ends.
I've tried another ways to run a daemon (one line per one attempt of course) but with the same poor result:
thread.start_new_thread(os.system, ('/usr/sbin/httpd',))
process = subprocess.Popen("/usr/sbin/httpd", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
res = subprocess.call(["/usr/sbin/httpd", "&"])
res = subprocess.Popen("/usr/sbin/httpd")
res = os.system("/usr/sbin/httpd &")
res = os.spawnl(os.P_NOWAITO, '/usr/sbin/httpd', '&')
I've found the similar question but I cannot use start-stop-daemon since I work under RHEL6.3: Why hangs the web page after it started a daemon on the underlying server?