Kaydet (Commit) 3b1e6b2f authored tarafından Gregory P. Smith's avatar Gregory P. Smith

- Issue #3309: Fix bz2.BZFile itererator to release its internal lock

  properly when raising an exception due to the bz2file being closed.
  Prevents a deadlock.
üst 0f7cddc3
...@@ -112,6 +112,17 @@ class BZ2FileTest(BaseTest): ...@@ -112,6 +112,17 @@ class BZ2FileTest(BaseTest):
self.assertEqual(list(iter(bz2f)), sio.readlines()) self.assertEqual(list(iter(bz2f)), sio.readlines())
bz2f.close() 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): def testXReadLines(self):
# "Test BZ2File.xreadlines()" # "Test BZ2File.xreadlines()"
self.createTempFile() self.createTempFile()
......
...@@ -68,6 +68,10 @@ Library ...@@ -68,6 +68,10 @@ Library
- Issue #2113: Fix error in subprocess.Popen if the select system call is - Issue #2113: Fix error in subprocess.Popen if the select system call is
interrupted by a signal. interrupted by a signal.
- Issue #3309: Fix bz2.BZFile itererator to release its internal lock
properly when raising an exception due to the bz2file being closed.
Prevents a deadlock.
Build Build
----- -----
......
...@@ -1451,6 +1451,7 @@ BZ2File_iternext(BZ2FileObject *self) ...@@ -1451,6 +1451,7 @@ BZ2File_iternext(BZ2FileObject *self)
PyStringObject* ret; PyStringObject* ret;
ACQUIRE_LOCK(self); ACQUIRE_LOCK(self);
if (self->mode == MODE_CLOSED) { if (self->mode == MODE_CLOSED) {
RELEASE_LOCK(self);
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"I/O operation on closed file"); "I/O operation on closed file");
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment