diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2009-08-29 18:14:40 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2009-08-29 18:14:40 (GMT) |
commit | fff896b3090a9257a81f83eb812ea6940d15643d (patch) | |
tree | 7b2cc94c90a444ff3056b036e575f406646ad691 /Lib | |
parent | 3092ed977fa601c68469a61e7366eaa40c77bb7b (diff) | |
download | cpython-fff896b3090a9257a81f83eb812ea6940d15643d.zip cpython-fff896b3090a9257a81f83eb812ea6940d15643d.tar.gz cpython-fff896b3090a9257a81f83eb812ea6940d15643d.tar.bz2 |
#6750: TextIOWrapped could duplicate output when several threads write to it.
this affect text files opened with io.open(), and the print() function of py3k
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index edb593b..4288f1b 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2061,6 +2061,27 @@ class TextIOWrapperTest(unittest.TestCase): self.assertEqual(f.errors, "replace") + def test_threads_write(self): + # Issue6750: concurrent writes could duplicate data + event = threading.Event() + with self.open(support.TESTFN, "w", buffering=1) as f: + def run(n): + text = "Thread%03d\n" % n + event.wait() + f.write(text) + threads = [threading.Thread(target=lambda n=x: run(n)) + for x in range(20)] + for t in threads: + t.start() + time.sleep(0.02) + event.set() + for t in threads: + t.join() + with self.open(support.TESTFN) as f: + content = f.read() + for n in range(20): + self.assertEquals(content.count("Thread%03d\n" % n), 1) + class CTextIOWrapperTest(TextIOWrapperTest): def test_initialization(self): |