/main.py

http://radioappz.googlecode.com/ · 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. import os
  18. import sys
  19. import logging
  20. # Google App Engine imports.
  21. from google.appengine.ext.webapp import util
  22. # A workaround to fix the partial initialization of Django before we are ready
  23. from django.conf import settings
  24. settings._target = None
  25. os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
  26. # Import various parts of Django.
  27. import django.core.handlers.wsgi
  28. import django.core.signals
  29. import django.dispatch.dispatcher
  30. import django.db
  31. def log_exception(*args, **kwds):
  32. """Log the current exception.
  33. Invoked when a Django request raises an exception"""
  34. logging.exception("Exception in request:")
  35. # Log errors
  36. django.dispatch.dispatcher.connect(
  37. log_exception,
  38. django.core.signals.got_request_exception)
  39. # Unregister the rollback event handler
  40. django.dispatch.dispatcher.disconnect(
  41. django.db._rollback_on_exception,
  42. django.core.signals.got_request_exception)
  43. def main():
  44. # Create a Django application for WSGI.
  45. application = django.core.handlers.wsgi.WSGIHandler()
  46. # Run the WSGI CGI handler with that application.
  47. util.run_wsgi_app(application)
  48. if __name__ == '__main__':
  49. main()