[Python-checkins] r65790 - in python/branches/release25-maint: Lib/test/test_bz2.py Misc/NEWS Modules/bz2module.c

gregory.p.smith python-checkins at python.org
Mon Aug 18 01:06:19 CEST 2008


Author: gregory.p.smith
Date: Mon Aug 18 01:06:19 2008
New Revision: 65790

Log:
Backport of r64767 from trunk

Fixes Issue #3309: Fix bz2.BZFile iterator to release its internal lock
properly when raising an exception due to the bz2file being closed.
Prevents a deadlock.


Modified:
   python/branches/release25-maint/Lib/test/test_bz2.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Modules/bz2module.c

Modified: python/branches/release25-maint/Lib/test/test_bz2.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_bz2.py	(original)
+++ python/branches/release25-maint/Lib/test/test_bz2.py	Mon Aug 18 01:06:19 2008
@@ -110,6 +110,17 @@
         self.assertEqual(list(iter(bz2f)), sio.readlines())
         bz2f.close()
 
+    def testClosedIteratorDeadlock(self):
+        # "Test that iteration on a closed bz2file releases the lock."
+        # http://bugs.python.org/issue3309
+        self.createTempFile()
+        bz2f = BZ2File(self.filename)
+        bz2f.close()
+        self.assertRaises(ValueError, bz2f.next)
+        # This call will deadlock of the above .next call failed to
+        # release the lock.
+        self.assertRaises(ValueError, bz2f.readlines)
+
     def testXReadLines(self):
         # "Test BZ2File.xreadlines()"
         self.createTempFile()

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Mon Aug 18 01:06:19 2008
@@ -148,6 +148,10 @@
   up in the child process to prevent deadlock and report proper thread counts
   if the new process uses the threading module.
 
+- Issue #3309: Fix bz2.BZFile iterator to release its internal lock
+  properly when raising an exception due to the bz2file being closed.
+  Prevents a deadlock.
+
 
 Extension Modules
 -----------------

Modified: python/branches/release25-maint/Modules/bz2module.c
==============================================================================
--- python/branches/release25-maint/Modules/bz2module.c	(original)
+++ python/branches/release25-maint/Modules/bz2module.c	Mon Aug 18 01:06:19 2008
@@ -1437,6 +1437,7 @@
 	PyStringObject* ret;
 	ACQUIRE_LOCK(self);
 	if (self->mode == MODE_CLOSED) {
+                RELEASE_LOCK(self);
 		PyErr_SetString(PyExc_ValueError,
 				"I/O operation on closed file");
 		return NULL;


More information about the Python-checkins mailing list