Reputation: 20150
In WSGI file, we would import a py file as
from <pyFile> import app as application
but is it possible to load several py file into a single wsgi file by doing something like this:
from <pyFile1> import app1 as application
from <pyFile2> import app2 as application
I've tried the above, and it doesn't work.
Is there a different way to achieve this?
Upvotes: 2
Views: 428
Reputation: 174624
If uwsgi is your implementation of choice, consider this:
import uwsgi
from <pyFile1> import app1 as application1
from <pyFile2> import app2 as application2
uwsgi.applications = {'':application1, '/app2':application2}
Upvotes: 2
Reputation: 22659
You can't import various modules as the same name
, e.g.
from moduleX import somevar as X
from moduleY import othervar as X
Results in X == othervar
.
But anyway you can't have multiple applications running in the same instance of Python. That's because
The application object is simply a callable object that accepts two arguments [PEP 333].
Now, a simple WSGI application is something like:
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']
As you can see, there is no place here to make multiple applications working at the same time, due to the fact that every request is passed to ONE particular application callback.
Upvotes: 0