简体   繁体   中英

Is Python logging thread safe still from within a docker container?

I'm trying to contenerise a Python application that relies on logging . This library is declared to be thread safe. I'm just not sure "how safe" it is.

My idea es to run the docker container as docker run --rm -it my_container . This will create a log file within the container, that will be mapped to the filesystem in the host using volume (not explicitly shown in the command above because I still didn't sort out how to do that). Now, in practice, there will be several of such containers running in parallel in the host, all sharing the same log file (once I figure out how to do that).

Is this still thread safe? To what level is the safety implemented? We are not talking about "system threads", but different processes in different containers. They only share the file. Is this enough to ensure safeness in adding new lines from various processes without messing the file?

If you are running multiple Docker containers, then you are running multiple processes. Thread safety relates to contention between multiple threads in a single process, so thread safety is irrelevant in this situation. Refer to the official documentation relating to logging from multiple processes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM