changeset: 74473:2fb93282887a user: Nadeem Vawda date: Wed Jan 18 01:57:14 2012 +0200 files: Lib/bz2.py Lib/test/test_bz2.py Misc/NEWS description: Issue #13809: Make bz2 module work with threads disabled. Original patch by Amaury Forgeot d'Arc. diff -r a108818aaa0d -r 2fb93282887a Lib/bz2.py --- a/Lib/bz2.py Wed Jan 18 00:22:06 2012 +0100 +++ b/Lib/bz2.py Wed Jan 18 01:57:14 2012 +0200 @@ -10,9 +10,13 @@ __author__ = "Nadeem Vawda " import io -import threading import warnings +try: + from threading import RLock +except ImportError: + from dummy_threading import RLock + from _bz2 import BZ2Compressor, BZ2Decompressor @@ -53,7 +57,7 @@ """ # This lock must be recursive, so that BufferedIOBase's # readline(), readlines() and writelines() don't deadlock. - self._lock = threading.RLock() + self._lock = RLock() self._fp = None self._closefp = False self._mode = _MODE_CLOSED diff -r a108818aaa0d -r 2fb93282887a Lib/test/test_bz2.py --- a/Lib/test/test_bz2.py Wed Jan 18 00:22:06 2012 +0100 +++ b/Lib/test/test_bz2.py Wed Jan 18 01:57:14 2012 +0200 @@ -463,6 +463,13 @@ for t in threads: t.join() + def testWithoutThreading(self): + bz2 = support.import_fresh_module("bz2", blocked=("threading",)) + with bz2.BZ2File(self.filename, "wb") as f: + f.write(b"abc") + with bz2.BZ2File(self.filename, "rb") as f: + self.assertEqual(f.read(), b"abc") + def testMixedIterationAndReads(self): self.createTempFile() linelen = len(self.TEXT_LINES[0]) diff -r a108818aaa0d -r 2fb93282887a Misc/NEWS --- a/Misc/NEWS Wed Jan 18 00:22:06 2012 +0100 +++ b/Misc/NEWS Wed Jan 18 01:57:14 2012 +0200 @@ -447,6 +447,9 @@ Library ------- +- Issue #13809: Fix regression where bz2 module wouldn't work when threads are + disabled. Original patch by Amaury Forgeot d'Arc. + - Issue #13589: Fix some serialization primitives in the aifc module. Patch by Oleg Plakhotnyuk.

AltStyle によって変換されたページ (->オリジナル) /