How to get WSGI servers to close a connection after each response? How to get WSGI servers to close a connection after each response? flask flask

How to get WSGI servers to close a connection after each response?


This is really predicated on your WSGI server you are hosting your framework via. The best solution with bottle is to run it through gevent.

botapp = bottle.app()for Route in (mainappRoute,): #handle multiple files containing routes    botapp.merge(Route)botapp = SessionMiddleware(botapp, beakerconfig) #in case you are using beaker sessionsbotapp = WhiteNoise(botapp) #in case you want whitenoise to handle static filesbotapp.add_files(staticfolder, prefix='static/') #add static route to whitenoiseserver = WSGIServer(("0.0.0.0", int(80)), botapp) #gevent async web serverdef shutdown():    print('Shutting down ...')    server.stop(timeout=60)    exit(signal.SIGTERM)gevent.signal(signal.SIGTERM, shutdown)gevent.signal(signal.SIGINT, shutdown) #CTRL Cserver.serve_forever() #spawn the server

You can purge the whitenoise and bottle configs if they aren't necessary, I kept them there as an example, and a suggestion that you use them if this is outward facing.

This is purely asynchronous on every connection.