old_contents: 
  import sys
  
  from eventlet import api
  from eventlet import httpc
  
  from eventlet.hubs import nginx
  
  
  def real_application(env, start_response):
      #result = httpc.get('http://127.0.0.1:8081/')
      start_response('200 OK', [('Content-type', 'text/plain')])
      #sys.stderr.write("RESULT %r" % (result, ))
      return 'hi'
  
  
  def wrap_application(master, env, start_response):
      result = real_application(env, start_response)
      ## Should catch exception and return here?
      #sys.stderr.write("RESULT2 %r" % (result, ))
      master.switch((result, None))
      return None, None
  
  
  def application(env, start_response):
      hub = api.get_hub()
  
      if not isinstance(hub, nginx.Hub):
          api.use_hub(nginx)
  
      hub.poll_register = env['ngx.poll_register']
      hub.poll_unregister = env['ngx.poll_unregister']
      hub.sleep = env['ngx.sleep']
      hub.current_application = api.getcurrent()
  
      slave = api.greenlet.greenlet(wrap_application)
      result = slave.switch(
          hub.current_application, env, start_response)
  
      while True:
          #sys.stderr.write("RESULT3 %r" % (result, ))
          if result is None or result == (None, None):
              yield ''
          else:
              if isinstance(result, tuple):
                  yield result[0]
              else:
                  yield result
              return
          result = hub.switch()
  
new_contents: 
  import sys
  import traceback
  
  sys.path.insert(0, '/Users/donovan/Code/mulib-hg')
  sys.stdout = sys.stderr
  
  from eventlet import api
  from eventlet import httpc
  
  from eventlet.hubs import nginx
  
  
  def old_real_application(env, start_response):
      #result = httpc.get('http://127.0.0.1:8081/')
      start_response('200 OK', [('Content-type', 'text/plain')])
      #sys.stderr.write("RESULT %r" % (result, ))
      return 'hello'
  
  
  def wrap_application(master, env, start_response):
      real_application = api.named(env['eventlet_nginx_wsgi_app'])
      result = real_application(env, start_response)
      ## Should catch exception and return here?
      #sys.stderr.write("RESULT2 %r" % (result, ))
      master.switch((result, None))
      return None, None
  
  
  class StartResponse(object):
      def __init__(self, start_response):
          self.start_response = start_response
  
      def __call__(self, *args):
          self.args = args
  
  
  def application(env, start_response):
      hub = api.get_hub()
  
      if not isinstance(hub, nginx.Hub):
          api.use_hub(nginx)
  
      hub.poll_register = env['ngx.poll_register']
      hub.poll_unregister = env['ngx.poll_unregister']
      hub.sleep = env['ngx.sleep']
      hub.current_application = api.getcurrent()
  
      slave = api.greenlet.greenlet(wrap_application)
      response = StartResponse(start_response)
      result = slave.switch(
          hub.current_application, env, response)
  
      while True:
          #sys.stderr.write("RESULT3 %r" % (result, ))
          if result is None or result == (None, None):
              yield ''
          else:
              start_response(*response.args)
              if isinstance(result, tuple):
                  for x in result[0]:
                      yield x
              else:
                  for x in result:
                      yield x
              return
          result = hub.switch()
  
subject: Use a couple of environment variables to figure out what wsgi app to really run in nginx_mod_wsgi.py. Now you can run any wsgi app you want easily in nginx. Also, delay calling start_response until the first hunk of the body is sent since nginx doesn't let us change the response codes or headers after the first time it is called.