/main.py
Python | 61 lines | 24 code | 12 blank | 25 comment | 1 complexity | 154f4fd68debab2d9adddc08e7954e40 MD5 | raw file
1#!/usr/bin/env python 2# 3# Copyright 2008 Google Inc. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import os 19import sys 20import logging 21 22# Google App Engine imports. 23from google.appengine.ext.webapp import util 24 25# A workaround to fix the partial initialization of Django before we are ready 26from django.conf import settings 27settings._target = None 28 29os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 30 31# Import various parts of Django. 32import django.core.handlers.wsgi 33import django.core.signals 34import django.dispatch.dispatcher 35import django.db 36 37def log_exception(*args, **kwds): 38 """Log the current exception. 39 Invoked when a Django request raises an exception""" 40 logging.exception("Exception in request:") 41 42# Log errors 43django.dispatch.dispatcher.connect( 44 log_exception, 45 django.core.signals.got_request_exception) 46 47# Unregister the rollback event handler 48django.dispatch.dispatcher.disconnect( 49 django.db._rollback_on_exception, 50 django.core.signals.got_request_exception) 51 52def main(): 53 # Create a Django application for WSGI. 54 application = django.core.handlers.wsgi.WSGIHandler() 55 56 # Run the WSGI CGI handler with that application. 57 util.run_wsgi_app(application) 58 59 60if __name__ == '__main__': 61 main()