Answer the question
In order to leave comments, you need to log in
How to poison the response to a POST request before the script completes?
Colleagues, I ask you to help in this matter.
If a telegram is a bot that sends a post request to the server and receives a response.
The responses can be different in the duration of the script, and when the server does not respond for more than 60 seconds, the telegram sends a second request.
How to send response like "200" before script ends?
from app import app
from flask import request, render_template
from .models import Users
from .classes import Base
from .controller import *
from flask_bootstrap import Bootstrap
@app.route("/", methods=["GET", "POST"])
def receive_update():
if request.method == "POST":
<...>
return "ok"
Answer the question
In order to leave comments, you need to log in
I used for such rq worker + redis
i.e. you send the necessary tasks to the redis queue
rq worker sees the task and starts executing it to
the front along with 200 you give a list of task ids and from time to time polish their status
here https://blog.miguelgrinberg.com/post/the-flask-meg ...
The HTTP protocol is a request-response (except for ws and sse), i.e. the response implies the end of processing the request. Usually background execution is used for long tasks, the most famous example of celery, but for many tasks it is an overhead and there are simpler solutions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question