Are file.write atoms in Python or C?
Example
Consider the following two threads
Theme 1
with open('foo', 'a') as f: f.write('123456')
Theme 2
with open('foo', 'a') as f: f.write('abcdef')
Are we guaranteed that we do not get mixed text as follows?
1a2b3c4d5e6f or 123abc456def
but instead get one of two possible correct results
123456abcdef abcdef123456
Note that there is one call to write in each thread, obviously, atomic multiple writes require some locking. I also know file locks. The ideal answer to this question is yes / no, as well as evidence / documentation.
source share