pyfilesystem
pyfilesystem copied to clipboard
Hang in Python 3.4
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
Confirmed. Looks like a bug in readline.
Original comment by willmcgugan on 16 Oct 2014 at 1:20
- Changed state: Accepted
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
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
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
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
That seems to have done the trick. Thanks.
Original comment by [email protected] on 18 Oct 2014 at 11:32