This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_gzip fails on OS X
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, pitrou
Priority: normal Keywords:

Created on 2010-05-04 18:18 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg104965 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-04 18:18
test_buffered_reader test_gzip is failing for me since r80720, on trunk on OS X 10.6.3:

======================================================================
ERROR: test_buffered_reader (__main__.TestGzip)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_gzip.py", line 91, in test_buffered_reader
    lines = [line for line in r]
  File "/Users/dickinsm/python/svn/trunk/Lib/gzip.py", line 365, in flush
    self.fileobj.flush()
IOError: [Errno 9] Bad file descriptor

----------------------------------------------------------------------
Ran 16 tests in 1.258s

FAILED (errors=1)
Traceback (most recent call last):
  File "Lib/test/test_gzip.py", line 271, in <module>
    test_main(verbose=True)
  File "Lib/test/test_gzip.py", line 268, in test_main
    test_support.run_unittest(TestGzip)
  File "/Users/dickinsm/python/svn/trunk/Lib/test/test_support.py", line 1038, in run_unittest
    _run_suite(suite)
  File "/Users/dickinsm/python/svn/trunk/Lib/test/test_support.py", line 1021, in _run_suite
    raise TestFailed(err)
test.test_support.TestFailed: Traceback (most recent call last):
  File "Lib/test/test_gzip.py", line 91, in test_buffered_reader
    lines = [line for line in r]
  File "/Users/dickinsm/python/svn/trunk/Lib/gzip.py", line 365, in flush
    self.fileobj.flush()
IOError: [Errno 9] Bad file descriptor


Here's a minimal Python script that produces the failure:

import gzip
import io

f = gzip.GzipFile('hamster', 'wb')
f.write("some data")
f.close()

f = gzip.GzipFile('hamster', 'rb')
r = io.BufferedReader(f)
lines = [line for line in r]
r.close()

This gives the following output:

Traceback (most recent call last):
  File "test_gzip.py", line 11, in <module>
    r.close()
  File "/Users/dickinsm/python/svn/trunk/Lib/gzip.py", line 365, in flush
    self.fileobj.flush()
IOError: [Errno 9] Bad file descriptor
[20213 refs]
msg104966 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-05-04 18:19
Can you try the following:

>>> f = open('LICENSE', 'rb')
>>> f.flush()
msg104968 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-04 18:28
Yep, that's enough to trigger it:

Python 2.7b1+ (trunk:80760, May  4 2010, 19:27:27) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('LICENSE', 'rb')
[35032 refs]
>>> f.flush()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
[35067 refs]
msg104969 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-05-04 18:29
Ok, can you try the following patch then:

Index: Lib/gzip.py
===================================================================
--- Lib/gzip.py	(révision 80760)
+++ Lib/gzip.py	(copie de travail)
@@ -362,7 +362,7 @@
         if self.mode == WRITE:
             # Ensure the compressor's buffer is flushed
             self.fileobj.write(self.compress.flush(zlib_mode))
-        self.fileobj.flush()
+            self.fileobj.flush()
 
     def fileno(self):
         """Invoke the underlying file object's fileno() method.
msg104971 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-04 18:30
That fixes the failure.
msg104973 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-04 18:49
Thanks, Antoine.  Applied in r80762 through r80765.
History
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52860
2010-05-04 18:49:15mark.dickinsonsetstatus: open -> closed
type: behavior
messages: + msg104973

resolution: fixed
stage: resolved
2010-05-04 18:30:52mark.dickinsonsetmessages: + msg104971
2010-05-04 18:29:43pitrousetmessages: + msg104969
2010-05-04 18:28:16mark.dickinsonsetmessages: + msg104968
2010-05-04 18:19:17pitrousetmessages: + msg104966
2010-05-04 18:18:03mark.dickinsoncreate