summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bz2.py8
-rw-r--r--Lib/test/test_bz2.py7
2 files changed, 13 insertions, 2 deletions
diff --git a/Lib/bz2.py b/Lib/bz2.py
index 5c59a9e..36e5558 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -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
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index bd40f83..0f8d149 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -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])