Replies: 2 comments
-
Pass And FWIW, aliasing Also, the general advice: Depending on what you want to do, a background task daemon like Celery that runs in a different process may be better than running a thread within your webapp itself. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much @ThiefMaster, it works! from flask import current_app, g
def my_function(app):
with app.app_context():
app.logger.info("Lorem ipsum")
g.something = "Dolor sit amet"
def enqueue_my_function(queue, app):
for chunk in my_function(app):
queue.put(chunk)
queue.put(None)
# ...
Thread(target=enqueue_my_function, args=(queue, current_app. _get_current_object())).start() I will have a look at background task daemon like Celery. |
Beta Was this translation helpful? Give feedback.
-
I loop over a list and start a Thread. I don’t have access to
flask.app
andflask.g
in the function executed by the Thread.I tried to pass app as a parameter with no success. Any idea?
I got this error:
I have read the documentation but still don’t understand the issue.
Beta Was this translation helpful? Give feedback.
All reactions