I am building a web application using Flask. I have subclassed the Flask object so that I can execute a piece of code before the application exits (the Flask object is destroyed). When I run this in my terminal and press ^ C, I donβt see βCan you hear me?β, So I assume that __del__() not called.
from flask import Flask class MyFlask (Flask): def __init__(self, import_name, static_path=None, static_url_path=None, static_folder='static', template_folder='templates', instance_path=None, instance_relative_config=False): Flask.__init__(self, import_name, static_path, static_url_path, static_folder, template_folder, instance_path, instance_relative_config)
I would like this code to be executed in the destructor, so that it works no matter how the application loads. those. app.run() when testing, gunicorn hello.py in production. Thanks!
source share