Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to clone a request to use it later?

Tags:

python

flask

Is it possible to clone the flask.request object to use it later? I want to send the cloned request to another thread to repeat the same job. How can I put the cloned object on top of the request stack?

like image 486
user2862163 Avatar asked Nov 06 '25 12:11

user2862163


1 Answers

It is as simple as copying environ object. It has a copy() method that does the trick:

environ = flask.request.environ.copy()

Now you can use app.request_context to push a new context (with the cloned environ) to the flask context stack:

with app.request_context(environ):
    ...
like image 184
user2862163 Avatar answered Nov 08 '25 09:11

user2862163



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!