2011-02-17 62 views
3

我在扭曲的世界初学者,所以第一次我试图让下扭曲配置我的工作Django项目,目前它的Django的测试服务器或Apache通过的mod_wsgi上运作良好。扭曲挂起,而守护进程

我跟着这个linkthis too配置设置的基础上,我有波纹管

给予server.py文件所以,为了Django应用程序与扭曲我用下面的代码集成,

import sys 
import os 

from twisted.application import internet, service 
from twisted.web import server, resource, wsgi, static 
from twisted.python import threadpool 
from twisted.internet import reactor 
from django.conf import settings 
import twresource # This file hold implementation of "Class Root". 


class ThreadPoolService(service.Service): 
    def __init__(self, pool): 
     self.pool = pool 

    def startService(self): 
     service.Service.startService(self) 
     self.pool.start() 

    def stopService(self): 
     service.Service.stopService(self) 
     self.pool.stop() 

class Root(resource.Resource): 
    def __init__(self, wsgi_resource): 
     resource.Resource.__init__(self) 
     self.wsgi_resource = wsgi_resource 

    def getChild(self, path, request): 
     path0 = request.prepath.pop(0) 
     request.postpath.insert(0, path0) 
     return self.wsgi_resource 

PORT = 8080 

# Environment setup for your Django project files: 
#insert it to first so our project will get first priority. 
sys.path.insert(0,"django_project") 
sys.path.insert(0,".") 

os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings' 
from django.core.handlers.wsgi import WSGIHandler 

def wsgi_resource(): 
    pool = threadpool.ThreadPool() 
    pool.start() 
    # Allow Ctrl-C to get you out cleanly: 
    reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) 
    wsgi_resource = wsgi.WSGIResource(reactor, pool, WSGIHandler()) 
    return wsgi_resource 


# Twisted Application Framework setup: 
application = service.Application('twisted-django') 

# WSGI container for Django, combine it with twisted.web.Resource: 
# XXX this is the only 'ugly' part: see the 'getChild' method in twresource.Root 

wsgi_root = wsgi_resource() 
root = Root(wsgi_root) 

#multi = service.MultiService() 
#pool = threadpool.ThreadPool() 
#tps = ThreadPoolService(pool) 
#tps.setServiceParent(multi) 
#resource = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) 
#root = twresource.Root(resource) 


#Admin Site media files 
#staticrsrc = static.File(os.path.join(os.path.abspath("."), "/usr/haridas/eclipse_workplace/skgargpms/django/contrib/admin/media/")) 
#root.putChild("admin/media", staticrsrc) 

# Serve it up: 
main_site = server.Site(root) 
#internet.TCPServer(PORT, main_site).setServiceParent(multi) 
internet.TCPServer(PORT, main_site).setServiceParent(application) 

#EOF. 

使用上面的代码使用“扭曲-ny server.py”行之有效的命令行,但是当我们运行它作为守护“扭曲-y server.py”它将挂断,但应用程序正在监听的端口8080.我可以使用telnet访问它。

我发现这个问题挂一些修正计算器,从本身。它帮助我使用下面给出的代码部分,它在上面的server.py文件中进行了评论。

multi = service.MultiService() 
pool = threadpool.ThreadPool() 
tps = ThreadPoolService(pool) 
tps.setServiceParent(multi) 
resource = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) 
root = twresource.Root(resource) 

和: -

internet.TCPServer(PORT, main_site).setServiceParent(multi) 

,而不是使用: -

wsgi_root = wsgi_resource() 
root = Root(wsgi_root) 

和: -

internet.TCPServer(PORT, main_site).setServiceParent(application) 

改进的方法也没有帮我避免悬而未决的问题。谁是成功的人在twisted守护进程模式下运行django应用程序?

我女仆任何错误,同时结合这些代码?目前,我才开始学习详细的扭曲结构。请帮我解决这个问题

我要找的扭曲应用程序配置(TAC)文件,该文件与扭曲的整合Django应用程序,并与出在守护模式也是任何问题运行。

感谢和问候,

Haridas N.

回答

4

我认为你是几乎没有。只需在最后添加一行:

multi.setServiceParent(application) 
+0

是的!,唯一缺失的就是那一行。现在事情运行良好,没有任何阻塞...... 谢谢你。 – 2011-06-30 06:22:46