Is chronological order of logging messages guaranteed?

北慕城南 提交于 2019-12-04 08:18:48

You can't be be 100% sure, I'm pretty sure.

Although the logging module locks the output file before writing to it, if you're running multiple threads or processes there's no guarantee that your code that called logging.warning("A") or whatever actually acquires the lock if several other threads are trying to do the same at around the same time.

See also the docs for logging and also its source. We see that it uses threading.RLock, about which the docs say:

If more than one thread is blocked waiting until the lock is unlocked, only one at a time will be able to grab ownership of the lock. There is no return value in this case.

We can't be entirely certain of which thread gets the lock first, which is the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!