I have a Django/Python application deployed(using gunicorn) with 9 workers with 5 thread each. Let's say if on a given time 45 requests are getting processed, Each thread is writing a lot of logs. How Django avoids writing logs for multiple threads at the same time? And how the file open and close works for each request(does this happen at each request, if yes, any other efficient way of logging)?
Asked
Active
Viewed 601 times
0
-
AFAIK, gunicorn uses its own loggers with the standard `logging` module. The logging module itself is [already thread-safe](https://docs.python.org/3.6/library/logging.html#thread-safety) and doesn't require you, or django/gunicorn, to do anything special in that regard. – sytech Mar 05 '18 at 21:00
1 Answers
0
The gunicorn logs will tell you a report on how the workers are being spawned and closed and their socket errors if any. Assuming you are question the django app logs, where you actually decide what you want to log and to which specific file, the workers are allowed to write the logs one-after-the-other i.e also thread safe, will never right over the other.
But this has its issues if you are trying to loggerate your logs e.g https://justinmontgomery.com/rotating-logs-with-multiple-workers-in-django

Wisani Salani
- 134
- 7