I'm trying to run two wsgi applications, one django and the other tilestache using the same server.

The tilestache server accesses the db via django to query the db. In the process of serving tiles it performs a transform on the incoming bbox, and in this process hit's the following error. The transform works without error for the specific bbox polygon when run manually from the python shell:

 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
   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

I think I've hit the non thread safe issue with GDAL, metioned on the django site. Is there a way I could configure this so that it would work?

Apache Version:

Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured

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 *: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

Django Version: 1.4


Listen 8080
NameVirtualHost *:8080


I've added the a test.wsgi script to determine if the GLOBAL interpreter setting is correct, as mentioned by graham and described here:


It seems to show the expected result:

[Tue Aug 14 10:32:01 2012] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations

[Tue Aug 14 10:32:01 2012] [info] mod_wsgi (pid=29891): Attach interpreter ''.

I've worked around the issue for now by changing the srs used in the db so that the transform is unnecessary in tilestache app. I don't understand why the transform() method, when called in the django app works, but then in the tilestache app fails.


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, "..", ".."))

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

tilestache_config_url = ""
application = TileStache.WSGITileServer(tilestache_config_url)


So it turned out I did need to use a projection other than the google (900913) one in the db. So my previous workaround failed.

While I'd like to fix this issue, I decided to work around the issue this type by making a django view that performs the transform needed. So now tilestache requests the data through the django app and not internally.

1 Answer 1


Your configuration is already single threaded, that is what 'threads=1' for daemon processes does. Try instead forcing use of main interpreter by adding:

WSGIApplicationGroup %{GLOBAL}

Some Python packages do not work properly in sub interpreters.

Also be aware that it is bad practice security wise to set DocumentRoot to be a parent directory of where your source code is. Leave DocumentRoot out and let it default to global document root, or set it to point at an empty directory. That way if you stuff things up at some point you don't risk your source code being downloadable.

  • Thanks for the info, and tip on docroot! I'm on vacation for awhile from tomorrow, when I get back next week I'll see if I can work this out.
    – monkut
    Aug 1, 2012 at 11:52
  • I tried setting this value, but unfortunately I saw the same error. I retested and the ogr exception doesn't occur in when run manually from the console. For now I've switched to another library as a work around to this problem.
    – monkut
    Aug 6, 2012 at 5:34
  • Verify you set it and reset server properly. code.google.com/p/modwsgi/wiki/… Aug 6, 2012 at 11:26
  • Thanks again, I've tried and from what I can see it seems ok, interpreter shows as ''. I suspect there's something strange in my system's configuration, but since I've managed to work around the issue for now, I'll let it rest.
    – monkut
    Aug 14, 2012 at 1:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .