from flask import current_app from threading import Thread from app import db from app.models import User from . import bp @bp.route('/users//delete', methods=['DELETE']) def delete_user(user_id): def _delete_user(app, user_id): with app.app_context(): user = User.query.get(user_id) user.delete() db.session.commit() User.query.get_or_404(user_id) thread = Thread( target=_delete_user, args=(current_app._get_current_object(), user_id) ) thread.start() return {}, 202