Skip to content

Instantly share code, notes, and snippets.

@mseeks
Created February 10, 2024 01:57
Show Gist options
  • Save mseeks/8488100759063b542d8e174670c87ac5 to your computer and use it in GitHub Desktop.
Save mseeks/8488100759063b542d8e174670c87ac5 to your computer and use it in GitHub Desktop.
Example Flask app showing how to handle a webhook with an asynchronous task using threading, returning a 200 response immediately.
from flask import Flask, request
from threading import Thread
app = Flask(__name__)
def async_task(data):
# Your async operation here, e.g., process data
pass
@app.route('/webhook', methods=['POST'])
def webhook():
data = request.json
# Run async_task in a separate thread
Thread(target=async_task, args=(data,)).start()
# Immediately return a 200 response to the webhook source
return 'OK', 200
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment