在多个域(虚拟主机)上运行多个 python Web 应用程序?
我被困住了,绝望了。
是否可以使用 Cherrypy 上的虚拟主机在多个不同域上提供多个 Python Web 应用程序?嗯等等...我会回答自己:是的,这是可能的。使用虚拟主机调度程序这是可能的,直到我需要这个:
我需要使用同一应用程序但在不同版本中的更多实例。这意味着我需要以某种方式分割这些应用程序的 python import
的命名空间。
例子: 我有应用程序 MyApp
并且它有两个版本。我有两个域 app1.com
和 app2.com
。 当我访问 app1.com
时,我想获取版本 1 中的应用程序 MyApp
。当我访问 app2.com
时,它应该是 < code>MyApp 在版本 2 中。
我现在使用 cherrypy 3.2
的 VirtualHostDispatcher
,问题是,当我使用从 的方法导入时>我的应用程序
版本 1 和 MyApp
版本 2 之前已加载,python 将使用已导入的模块(因为模块缓存)。
是的..每次都可以包装导入并清理python模块缓存(我将其用于顶级应用程序对象实例化),但对我来说似乎很不干净...而且我认为它效率也很低..那么
,你推荐我什么? 我正在考虑使用 Mod_WSGI 来使用 apache2 和cherrypy,但这似乎并不能解决导入问题,因为所有应用程序仍然有一个 python 进程。
也许,我对整个问题的思考完全错误,我需要重新思考。我乐于接受每一个想法或建议。唯一的限制是我想使用 Python 3。其他任何内容仍然可供讨论:-)
感谢您的每一个回复!
I am stuck and desperate.
Is it possible to serve multiple python web applications on multiple different domains using virtualhost on cherrypy? Hmm wait... I will answer myself: Yes, it is possible. With virtual host dispatcher it is possible, until i require this:
I need to use more instances of same application but in different versions. This means that I need to somehow split the namespace for the python import
for these applications.
Example:
I have application MyApp
and there are two versions of it. I have got two domains app1.com
and app2.com
.
When I access app1.com
I would like to get the application MyApp
in version 1. When I access app2.com
, it should be MyApp
in version 2.
I am now using the VirtualHostDispatcher
of cherrypy 3.2
and the problem is that, when I use import from the methods of MyApp
version 1 and the MyApp
version 2 has been loaded before, python will use the already imported module (because of module cache).
Yes.. it is possible to wrap the import and clean the python module cache everytime (i use this for the top level application object instantiation), but it seems quite unclean for me... And I think that it is also inefficient...
So, what do you recommend me?
I was thinking about using apache2 and cherrypy using Mod_WSGI, but it seems that this does not solve the import
problem, becuase there is still one python process for all apps togetger.
Maybe, I am thinking about the whole problem completely wrong and I will need to re-think it. I am opened for every idea or tip. Only limitation is that i want to use Python 3. Anything else is still opened for discussion :-)
Thank you for every response!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apache/mod_wsgi 可以完成所需的操作。 mod_wsgi 下安装的每个 Web 应用程序都将在同一进程中的不同子解释器中运行,因此可以使用不同的代码库。更好的是,您使用 mod_wsgi 的守护进程模式并将每个 Web 应用程序委托给不同的进程,这样就不会存在它们相互干扰的风险。
Apache/mod_wsgi can do what is required. Each mounted web application under mod_wsgi will run in a distinct sub interpreter in the same process so can be using different code bases. Better still, you use daemon mode of mod_wsgi and delegate each web application to distinct process so not risk of them interfering with each other.
创建像这样的 myapp_selector 模块怎么样:
what about creating myapp_selector module that does smth like that: