Posted By

vas3k on 01/20/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

saman


Python run WSGI by paste


 / Published in: Python
 

  1. import sys
  2. import os
  3. from time import sleep
  4. from traceback import print_exc
  5.  
  6. from paste.httpserver import serve
  7. from paste.evalexception import EvalException
  8. from paste.debug.prints import PrintDebugMiddleware
  9. from paste import reloader
  10.  
  11. def run_script(script):
  12. if not os.path.isfile(script):
  13. print script, "does not exist"
  14. sys.exit(1)
  15. reloader.install()
  16. reloader.watch_file(script)
  17.  
  18. script_locals = {}
  19. execfile(script, {'__file__': script}, script_locals)
  20. app = script_locals['application']
  21. app = EvalException(app)
  22. app = PrintDebugMiddleware(app)
  23. serve(app)
  24.  
  25. if __name__ == '__main__':
  26. try:
  27. run_script(sys.argv[0])
  28. except SystemExit, exc:
  29. raise exc
  30. except:
  31. print_exc()
  32. print '-' * 20, 'Restarting in 5 secs..', '-' * 20
  33. sleep(5)
  34. sys.exit(3)

Report this snippet  

You need to login to post a comment.