您的位置:首页 > 运维架构 > Apache

apache+mod_wsgi部署quixote的方法

2009-06-19 15:00 363 查看
折腾了好几天,终于搞定,特此记录,如有大牛发现方法有所不妥,请指正一下,不胜感激涕零........
  过程如下:
  假设python2.5和quixote你已经安装了
  1.安装apache2.2 ,过程略
  2.下载mod_wsgi.so
  3.copy到apache的modlues目录下
  4.给quixote准备连接mod_wsgi的脚本,代码如下:
  由于qwip需要支持多线程的publisher,所以需要继承publisher实现多线程支持,实现的例子在quixote的demo文件夹中有,代码:

#multi thread support
2import thread
3class ThreadedPublisher (Publisher):
4 is_thread_safe = True
5 def __init__ (self, root_namespace, config=None):
6 Publisher.__init__(self, root_namespace, config)
7 self._request_dict = {}
8 def _set_request(self, request):
9 self._request_dict[thread.get_ident()] = request
def _clear_request(self):
try:
del self._request_dict[thread.get_ident()]
except KeyError:
pass
def get_request(self):
return self._request_dict.get(thread.get_ident())
  
  注意 is_thread_safe = True 这一行是例子中没有的,但是必须加,不然qwip会认为你的publisher不是线程安全的,哪怕你已经做了多线程的处理。
  
  有了这个类之后就简单了,只需要:

def create_publisher():
2 #return Publisher(RootDirectory(),
3 # display_exceptions='plain')
4 return ThreadedPublisher(RootDirectory())
5
6import traceback
7from quixote import get_wsgi_app
8
9try:
pub = create_publisher()
application = get_wsgi_app()
except TypeError,e:
pass  
  注意application = get_wsgi_app()这个对象名称必须是application,不然mod_wsgi找不到能调用的东西。
  
  5.有了连接的脚本后就只需要配置mod_wsgi就行了
WSGIScriptAlias /test D:/WorkPlace/alex/TestQuixote/wsgi.py
<Directory D:/WorkPlace/alex/TestQuixote/>
   WSGIApplicationGroup %{GLOBAL}
   Order deny,allow
   Allow from all
</Directory>

  我这里配置了一个目录,其余的可以举一反三
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: