PyFilesystem / pyfilesystem

Python filesystem abstraction layer
http://pyfilesystem.org/
BSD 3-Clause "New" or "Revised" License
287 stars 63 forks source link

Hang in Python 3.4 #187

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This program hangs in Python 3.4 (Windows):
#!/usr/bin/env python
<CODE>
import fs.opener

with fs.opener.fsopen("a.txt") as f:
    for l in f:
        print(l)
</CODE>

The file a.txt should exist. Runs fine on 2.7.

Original issue reported on code.google.com by shewitt...@gmail.com on 16 Oct 2014 at 7:09

GoogleCodeExporter commented 9 years ago
Oops. fs version 0.5.0

Original comment by shewitt...@gmail.com on 16 Oct 2014 at 7:11

GoogleCodeExporter commented 9 years ago
Confirmed. Looks like a bug in readline.

Original comment by willmcgugan on 16 Oct 2014 at 1:20

GoogleCodeExporter commented 9 years ago
Pushed some changes to SVN. Please let me know if it fixes the problem.

Original comment by willmcgugan on 16 Oct 2014 at 2:16

GoogleCodeExporter commented 9 years ago
No, the problem still seems to exist.
Seems to be in 'filelike.py' line 660:

    def _read(self,sizehint=-1):
        data = self.wrapped_file.read(sizehint)
        if data == b(""): #660
            return None
        return data

>>> print(repr(data))
''
>>> print(type(data))
<class 'str'>
>>> print(repr(b("")))
b''
>>> print(type(b("")))
<class 'bytes'>

Original comment by shewitt...@gmail.com on 16 Oct 2014 at 5:43

GoogleCodeExporter commented 9 years ago
Actually that doesn't fix it, although it is a bug. Another pops up. It seems 
there are a few problems here.

Original comment by shewitt...@gmail.com on 17 Oct 2014 at 3:23

GoogleCodeExporter commented 9 years ago
It was the fsopen method that was at fault. There was a little bit of magic 
applied to the retuned file object to close the fs when the file was closed. 
Unfortunately that broke Py3 because it wasn't aware of unicode streams.

Anyway, I have used a different approach that works with Py2 & 3. Give that a 
try please.

Original comment by willmcgugan on 18 Oct 2014 at 11:07

GoogleCodeExporter commented 9 years ago
That seems to have done the trick. Thanks.

Original comment by shewitt...@gmail.com on 18 Oct 2014 at 11:32