我的 flask 项目使用 logging 模块,使用 TimedRotatingFileHandler,然后 gunicorn 开了 32 个进程.
logging 模块不是进程安全的,这个 logging 模块的官网有写
Because there is no standard way to serialize access to a single file across multiple processes in Python. If you need to log to a single file from multiple processes, one way of doing this is to have all the processes log to a SocketHandler, and have a separate process which implements a socket server which reads from the socket and logs to file. (If you prefer, you can dedicate one thread in one of the existing processes to perform this function.)
但是我的项目跑了半年,从来没有看到日志错乱的情况,每一条都清清楚楚..
但是看完了这个 issue 表示还是云里雾里没懂,gunicorn 作者给的解释如下
The fd is shared between all workers, and until it isn't over the limit (depending on your system) alls logs will go over it.
求详细解释,谢谢