title: WSGI with RESTful post-processing
body: <p>We have a WSGI application with Python3 running under Apache Linux.</p>
  
  <p>We want to interact with an external API after acknowledging a request / notification received via the Web server</p>
  
  <p>Sample WSGI python code:</p>
  
  <pre>
  def application(environ, start_response):
      path=  environ.get('PATH_INFO', '')   
      if path == "/ProcessTransact":
          import sys
          sys.stderr.write("Entering /ProcessTransact, Checking validity ...\n" )
          # Get the context of the notification/request from Post parameters etc, assume it is a valid ...
          status = '200 OK'  
          body = b"Acknowledge the valid submit with '200 OK'"
          response_headers = [
              ('Content-Type', 'text/html'),
              ('Content-Length', str(len(body)))
          ]
  
          start_response(status, response_headers)
          return [body]
  
          # we have acknowledged the context of the above request
          # we want to do an HTTP POST based on the context 
          # When we return [body], we lost the processing thread
  
          import requests           #or maybe something else
          sys.stderr.write("POST RESTful transactions here after acknowledging the request (we never get here).\n") 
  </pre>
  
  <p>Our code is slightly different to the sample code (using Werkzeug).</p>
  
  <p>What is the best way to solve this?
  We are purposefully not using any frameworks (except Werkzeug) and we want to avoid large changes in architecture (thousands of lines of code)</p>
  
  <p>Thank you,
  Kris</p>