我使用Django開發服務器來啓動後臺程序,它執行views.py中的所有命令,但網頁掛起。守護進程正常啓動,但網頁掛起需要修復。我在Red Hat Enterprise Linux 6.3下工作。Django網站服務器在啓動後臺程序後掛起
爲了確保這不是我或我進行以下測試我的後臺程序的錯誤:
1)我創造了新的Django項目「djtesting」,在那裏創建了下面的代碼一個views.py文件(它啓動httpd守護進程):
from django.http import HttpResponse
import subprocess
def hello(request):
res = subprocess.call("/usr/sbin/httpd")
return HttpResponse("Testing.")
2)增加此功能的urls.py:
from django.conf.urls.defaults import patterns, include, url
from djtesting.views import hello
urlpatterns = patterns('',
('^hello/$', hello),
)
3)然後,我開始的Web服務器「蟒蛇manage.py runserver命令192.168.1.226:8 000「,並在瀏覽器中打開」http://192.168.1.226:8000/hello/「的網頁。它顯示「測試」消息,然後掛起(開始加載並掛起),儘管守護進程正常啓動。但是,如果使用「/etc/init.d/httpd stop」停止守護進程,網頁將停止加載。看來服務器正在等待,直到守護進程完成工作,但我只需要啓動它,而不必等到它結束。
我已經試過其他的方式來運行一個後臺程序(每門課程的一個嘗試一條線),但同樣差的結果:
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', '&')
我已經找到了類似的問題,但我不能使用開始 - stop-daemon,因爲我在RHEL6.3下工作: Why hangs the web page after it started a daemon on the underlying server?
我有一些腳本來加載我的資料庫中的數據導致相同的問題。有進口django;頂部的django.setup()。他們工作得很好,然後突然他們開始阻塞服務器。直到我需要使用可用的腳本時,纔會對這些內容進行評論。 –