]> granicus.if.org Git - python/commitdiff
Issue #13809: Make bz2 module work with threads disabled.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Tue, 17 Jan 2012 23:57:14 +0000 (01:57 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Tue, 17 Jan 2012 23:57:14 +0000 (01:57 +0200)
Original patch by Amaury Forgeot d'Arc.

Lib/bz2.py
Lib/test/test_bz2.py
Misc/NEWS

index 5c59a9e08a487796c2c64f93251f298342229fde..36e55584ed7b656b31300110d5f7a1c0157ec48c 100644 (file)
@@ -10,9 +10,13 @@ __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "compress",
 __author__ = "Nadeem Vawda <nadeem.vawda@gmail.com>"
 
 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 @@ class BZ2File(io.BufferedIOBase):
         """
         # 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
index bd40f83fcf61d311570d9d471a2b8418ffedb05f..0f8d14910f43c1e65abe6c0ef503be6a0edc60ea 100644 (file)
@@ -463,6 +463,13 @@ class BZ2FileTest(BaseTest):
             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])
index 8178a92b89d5e91c9c2db6e6b5f559e8653734e0..246b3c1977e04042e773b019ddb7ef05c999c0ea 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -447,6 +447,9 @@ Core and Builtins
 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.