I have a Flask Service and I want to log a correlationID for all log messages. I found this blog post which makes use of threading.local()
.
My Flask service uses gunicorn and gevent:
gunicorn --worker-class=gevent \
--worker-connections=1000 \
--bind 0.0.0.0:5000 myapp.app:app
--workers=4 --timeout 120 --keep-alive 120
Can threading.local()
be used for a request?
I guess ...
- each worker is a different process and
- each connection is a different thread and
- each request is on exactly one thread, if I don't explicitly start another thread?
But when I start another thread, I would need to pass the correlationId explicitly, right?
(In case it matters: I use Python 3.7)