2011-02-17 3 views
3

저는 처음에는 트위스티드 세계에서 일하고 있습니다. 그래서 먼저 현재 작동중인 장고 프로젝트를 트위스트로 구성하려고합니다. 현재 mod_wsgi를 통해 장고 테스트 서버 나 아파치를 테스트하고 있습니다. 데몬스트레이션 중에 트위스트가 걸린다

는 나는 그래서에서 순서 나는 다음과 같은 코드를 사용 트위스트와 장고 응용 프로그램을 통합,

노호 주어진 server.py 파일이 그에 따라 설정을 구성하려면이 linkthis too을 따라

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. 

위의 코드를 사용하면 "twisted -ny server.py"를 사용하여 명령 행에서 제대로 작동하지만 "twisted -y server.py"데몬으로 실행하면 정지되지만 응용 프로그램이 포트를 수신합니다. 텔넷을 사용하여 액세스 할 수 있습니다.

stackoverflow 자체에서이 정지 문제에 대한 몇 가지 수정 사항을 발견했습니다. 위의 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) 

수정 방법은 날 도움이되지 않았다 교수형 문제를 피하십시오. 트위터 데몬 모드에서 장고 앱을 실행하십시오.

나는이 코드들을 결합하는 동안 실수를 저지른 적이 있습니까?, 현재 나는 꼬인 아키텍처를 자세히 배우기 시작했습니다. 이 문제를 해결할 수 있도록 도와주세요.

django 응용 프로그램을 꼬인 상태로 통합하고 데몬 모드에서도 문제가없는 Twisted Application configuration (TAC) 파일을 찾고 있습니다.

감사와 안부,

Haridas의 N.

답변

4

난 당신이 거의 생각합니다. 끝 부분에 하나 이상의 행을 추가하십시오.

multi.setServiceParent(application) 
+0

예! 누락 된 것은 그 행뿐입니다. 이제 막히는 일없이 잘 작동하는 것 .... 감사합니다. –

+1

반갑습니다. 공식적으로 내 대답을 받아들이시겠습니까? :) – mateolargo

+0

StackOverflow는 질문 포스터를 해고 할 때 Amazon과 Ebay가하는 일과 같은 미묘한 알림을 받아들이 기 위해 더 나은 작업을 수행해야합니다. 어떤 사람들은 항상 받아 들여야한다는 것을 기억하고, 그렇지 않은 사람들도 있습니다. : - / –

관련 문제