We have a WSGI application with Python3 running under Apache Linux.
We want to interact with an external API after acknowledging a request / notification received via the Web server
Sample WSGI python code:
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")
Our code is slightly different to the sample code (using Werkzeug).
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)
Thank you, Kris
atexit
callbacks only help when a process is shutdown. A process survives more than one request usually and so is of no use. WSGI defines an interface between a web server and a Python web application. a RESTful application is a style of writing an application. It needs something like WSGI to interface to the web server. So you are going to need WSGI and a server implementing the WSGI specification to be able to talk to most ways of hosting Python web applications. Your only other choice is Python async frameworks which implement own API. – Graham Dumpleton