2012-06-03 52 views
2

在WSGI文件,我們會導入PY文件可以WSGI負荷數瓶應用

from <pyFile> import app as application 

但有可能幾個PY文件加載到一個單一的WSGI文件做這樣的事情:

from <pyFile1> import app1 as application 
from <pyFile2> import app2 as application 

我已經試過以上,而這是行不通的。

是否有不同的方式來實現這一目標?

+0

,你會怎麼那麼名爲'application'兩個模塊之間區別? –

+0

闡明您正在使用的WSGI託管機制。有些人可以在同一個WSGI文件中擁有多個應用程序入口點,只要每個人的命名不同,並且WSGI服務器配置設置爲將不同的URL映射到它們。 –

回答

0

您不能導入各種模塊一樣name,例如

from moduleX import somevar as X 
from moduleY import othervar as X 

結果X == othervar

但是,無論如何你不能在Python的同一實例中運行多個應用程序。這是因爲

應用程序對象是一個簡單的可調用對象,它接受兩個參數[PEP 333]

現在,一個簡單的WSGI應用程序是這樣的:

def simple_app(environ, start_response): 
    """Simplest possible application object""" 
    status = '200 OK' 
    response_headers = [('Content-type', 'text/plain')] 
    start_response(status, response_headers) 
    return ['Hello world!\n'] 

正如你所看到的,這裏沒有地方,使多個應用程序同時工作,由於每個請求傳遞給一個特定的應用程序回調。

2

如果uwsgi是你選擇的實現,可以這樣考慮:

import uwsgi 

from <pyFile1> import app1 as application1 
from <pyFile2> import app2 as application2 

uwsgi.applications = {'':application1, '/app2':application2} 
當然這是行不通的