pyfilesystem icon indicating copy to clipboard operation
pyfilesystem copied to clipboard

Hang in Python 3.4

Open GoogleCodeExporter opened this issue 10 years ago • 7 comments

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 [email protected] on 16 Oct 2014 at 7:09

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter

Oops. fs version 0.5.0

Original comment by [email protected] on 16 Oct 2014 at 7:11

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter

Confirmed. Looks like a bug in readline.

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

  • Changed state: Accepted

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter

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

  • Changed state: Started

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter

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 [email protected] on 16 Oct 2014 at 5:43

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter

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 [email protected] on 17 Oct 2014 at 3:23

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter

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 avatar Apr 11 '15 10:04 GoogleCodeExporter

That seems to have done the trick. Thanks.

Original comment by [email protected] on 18 Oct 2014 at 11:32

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter