I spent several hours to figure this out, first about those issues:
- Atomicity of `write (2)` to the local file system
- How can I synchronize - produce atomic recording in one file from two processes?
- How to programmatically determine if there is a โrecordโ, a system call is atomic in a specific file?
- What happens if a write system call is called in the same file by two different processes at the same time?
- http://article.gmane.org/gmane.linux.kernel/43445
It seems that when opening the file we use the "O_APPEND" flag, it will always be normally registered in one file from several processes in Linux. And I believe that python necessarily uses the O_APPEND flag in its registration module.
And from a little test:
#!/bin/env python import os import logging logger = logging.getLogger('spam_application') logger.setLevel(logging.DEBUG)
And I launched it with
./test.py & ./test.py & ./test.py & ./test.py &
I found that there is nothing wrong with spam.log. This behavior may support the conclusion above.
But the problems that arise are:
- What does this mean here ?
- And what are the scenarios for using this , just to rotate the file?
Finally, if two processes write to the same file, I mean that they call (2) to the same file, which is sure that the data from the two processes do not alternate (kernel or file system?) And how. [NOTE: I just want to see in the back of the syscall script, any hit on this is welcome.]
EDIT1:
Do this and this just exist for compatibility between different os environments like windows, linux or mac?
EDIT2:
One more test, feed the 8K lines to logging.debug every time. And this time, I see the "rotation" behavior in spam.log. This behavior is simply indicated in PIPE_BUF one page above. So it seems that the behavior is clear on linux, using O_APPEND is ok if the size of the record (2) is less than PIPE_BUF.
python logging atomic multiprocessing atomicity
apporc Jul 6 '16 at 8:32 2016-07-06 08:32
source share