New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fileinput device or resource busy error #42514
Comments
Fileinput module can't work with the unicode path names Here is the reproduction of the error: ---------------8<---------------8<---------------8<---------------8<------- meren@pardus /home/meren $ touch myfile
meren@pardus /home/meren $ python
>>> fn = u'/home/meren/myfile'
>>> type(fn)
<type 'unicode'>
>>> import fileinput
>>> for line in fileinput.input(fn, inplace = 1):
... print line
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/fileinput.py", line 231, in next
line = self.readline()
File "/usr/lib/python2.3/fileinput.py", line 300, in
readline
os.rename(self._filename, self._backupfilename)
OSError: [Errno 16] Device or resource busy
>>>
--------------->8--------------->8--------------->8--------------->8 This is happening, because the value of the The __init__ method of the FileInput class ---------------8<---------------8<---------------8<---------------8<------- When the type of the 'files' variable is unicode, the files = [u'/', u'h', u'o', u'm', u'e', u'/', u'm',
u'e', u'r', u'e' .... consequently, python is trying to execute [1], [2] Checking the type of the variable in the __init__ Here is a small patch to show replacement properly: ---------------8<---------------8<---------------8<---------------8<------- def __init__(self, files=None, inplace=0,
backup="", bufsize=0):
- if type(files) == type(''):
+ if isinstance(files, basestring):
files = (files,)
else:
if files is None:
--------------->8--------------->8--------------->8--------------->8 and here is the result of the same operation after this ---------------8<---------------8<---------------8<---------------8<------- (...)
os.rename(self._filename, self._backupfilename)
OSError: [Errno 16] Device or resource busy
>>> reload(fileinput)
<module 'fileinput' from '/usr/lib/python2.3/fileinput.py'>
>>> for line in fileinput.input(fn, inplace = 1):
... print line
...
>>>
--------------->8--------------->8--------------->8--------------->8 Sorry for the long explanation, |
Logged In: YES Thanks for the report, applied your patch in rev. 42489, 42490. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: