diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-27 17:41:58 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-27 17:41:58 (GMT) |
commit | dd62966a5fbc502a0e8d91ca3a7de843f1800d99 (patch) | |
tree | e68ae98c2e5c19cbbe5cf0925c6fd841e2a58c4f /Lib/test | |
parent | 5098bc944849a7e9a355ae9647d740935893fad1 (diff) | |
download | cpython-dd62966a5fbc502a0e8d91ca3a7de843f1800d99.zip cpython-dd62966a5fbc502a0e8d91ca3a7de843f1800d99.tar.gz cpython-dd62966a5fbc502a0e8d91ca3a7de843f1800d99.tar.bz2 |
Issue #7205: Fix a possible deadlock when using a BZ2File object from several threads at once.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_bz2.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index 215a04e..f68586d 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -7,6 +7,7 @@ from cStringIO import StringIO import os import subprocess import sys +import threading bz2 = import_module('bz2') from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor @@ -306,6 +307,23 @@ class BZ2FileTest(BaseTest): else: self.fail("1/0 didn't raise an exception") + def testThreading(self): + # Using a BZ2File from several threads doesn't deadlock (issue #7205). + data = "1" * 2**20 + nthreads = 10 + f = bz2.BZ2File(self.filename, 'wb') + try: + def comp(): + for i in range(5): + f.write(data) + threads = [threading.Thread(target=comp) for i in range(nthreads)] + for t in threads: + t.start() + for t in threads: + t.join() + finally: + f.close() + class BZ2CompressorTest(BaseTest): def testCompress(self): |