我试图运行两个 wsgi应用程序,一个django和其他tilestache使用相同的服务器。
tilestache服务器通过django访问数据库来查询数据库。 在提供瓷砖的过程中,它会对传入的bbox执行转换,并在此过程中发生以下错误。 当从python shell手动运行时,转换对于特定的bbox多边形没有错误:
Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 325, in __call__ mimetype, content = requestHandler(self.config, environ['PATH_INFO'], environ['QUERY_STRING']) File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 231, in requestHandler mimetype, content = getTile(layer, coord, extension) File "/usr/lib/python2.7/dist-packages/TileStache/__init__.py", line 84, in getTile tile = layer.render(coord, format) File "/usr/lib/python2.7/dist-packages/TileStache/Core.py", line 295, in render tile = provider.renderArea(width, height, srs, xmin, ymin, xmax, ymax, coord.zoom) File "/var/www/tileserver/providers.py", line 59, in renderArea bbox.transform(METERS_SRID) File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/geos/geometry.py", line 520, in transform g = gdal.OGRGeometry(self.wkb, srid) File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/gdal/geometries.py", line 131, in __init__ self.__class__ = GEO_CLASSES[self.geom_type.num] File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/gdal/geometries.py", line 245, in geom_type return OGRGeomType(capi.get_geom_type(self.ptr)) File "/usr/local/lib/python2.7/dist-packages/django/contrib/gis/gdal/geomtype.py", line 43, in __init__ raise OGRException('Invalid OGR Integer Type: %d' % type_input) OGRException: Invalid OGR Integer Type: 1987180391
我想我已经在django网站上提到了GDAL的非线程安全问题。 有没有一种方法可以configuration这个,以便它能工作?
Apache版本:
Apache / 2.2.22(Ubuntu)mod_wsgi / 3.3configurationPython / 2.7.3
Apache apache2/sites-available/default :
<VirtualHost *:80> ServerAdmin ironman@localhost DocumentRoot /var/www/bin LogLevel warn WSGIDaemonProcess lbs processes=2 maximum-requests=500 threads=1 WSGIProcessGroup lbs WSGIScriptAlias / /var/www/bin/apache/django.wsgi Alias /static /var/www/lbs/static/ </VirtualHost> <VirtualHost *:8080> ServerAdmin ironman@localhost DocumentRoot /var/www/bin LogLevel warn WSGIDaemonProcess tilestache processes=1 maximum-requests=500 threads=1 WSGIProcessGroup tilestache WSGIScriptAlias / /var/www/bin/tileserver/tilestache.wsgi </VirtualHost>
Django版本: 1.4
httpd.conf中:
Listen 8080 NameVirtualHost *:8080
UPDATE
我已经添加了一个test.wsgi脚本来确定GLOBAL解释器设置是否正确,正如graham所述,并在这里描述:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Sub_Interpreter_Being_Used
它似乎显示了预期的结果:
[2012年8月14日10:32:01] [预告] Apache / 2.2.22(Ubuntu)mod_wsgi / 3.3 Python / 2.7.3configuration – 恢复正常操作
[星期二8月14日10:32:01 2012] [信息] mod_wsgi(pid = 29891):附加解释器''。
我已经解决了这个问题,现在通过更改数据库中使用的srs ,以便在tilestache应用程序中不需要转换。 我不明白为什么在django应用程序中调用transform()方法时,在tilestache应用程序中失败。
tilestache.wsgi
#!/usr/bin/python import os import time import sys import TileStache current_dir = os.path.abspath(os.path.dirname(__file__)) project_dir = os.path.realpath(os.path.join(current_dir, "..", "..")) sys.path.append(project_dir) sys.path.append(current_dir) os.environ['DJANGO_SETTINGS_MODULE'] = 'bin.settings' sys.stdout = sys.stderr # wait for the apache django lbs server to start up, # --> in order to retrieve the tilestache cfg time.sleep(2) tilestache_config_url = "http://127.0.0.1/tilestache/config/" application = TileStache.WSGITileServer(tilestache_config_url)
更新2
所以事实certificate,我确实需要使用投影之外的谷歌(900913)之一在分贝。 所以我以前的解决方法失败。
虽然我想解决这个问题,但我决定通过制作一个执行所需转换的django视图来解决这个问题。 所以现在tilestache通过django应用程序请求数据而不是内部。
您的configuration已经是单线程的,这就是守护进程的'threads = 1'。 试试通过添加以下内容来强制使用主要解释器:
WSGIApplicationGroup %{GLOBAL}
一些Python包在子解释器中不能正常工作。
另外请注意,将DocumentRoot设置为源代码所在的父目录是不安全的做法。 保持DocumentRoot不变,并将其默认为全局文档根目录,或将其设置为指向一个空目录。 那样的话,如果你在某个时候把东西搞砸了,那么你就不用担心你的源代码可以被下载。