Python version: 2.7.18 from the official Fedora repos.
Operating System: Fedora 5.8.10-200.fc32.x86_64
Description:
FileObject variants that inherit from FileObjectBase raise when accessing the name property after the file has been closed. The file object returned by io.open() doesn't have the same behavior, it returns the file path fine. This breaks some libraries (e.g. atomicwrites which rely on this behaviour.
It happens because in FileObjectCommon.close() we drop the reference to the wrapped object.
I can think of two possible fixes.
Don't drop the self._io reference in close(), instead set a self._closed = True flag to be used in __getattr__(), and add name in _delegate_methods().
In FileObjectCommon.__init__() do self.name = self._io.name.
Thoughts?
What I've run:
importgevent.monkey; gevent.monkey.patch_all()
importgevent.fileobjectimportiof=io.open("/tmp/foo", mode="w")
print("f.name by io.open before close: {}".format(f.name))
f.close()
print("f.name by io.open after close: {}".format(f.name))
f=gevent.fileobject.FileObjectThread(
"/tmp/foo",
mode="w",
)
print("f.name by gevent.fileobject before close: {}".format(f.name))
f.close()
print("f.name by gevent.fileobject after close: {}".format(f.name))
The text was updated successfully, but these errors were encountered:
Description:
FileObject
variants that inherit fromFileObjectBase
raise when accessing thename
property after the file has been closed. The file object returned byio.open()
doesn't have the same behavior, it returns the file path fine. This breaks some libraries (e.g. atomicwrites which rely on this behaviour.It happens because in
FileObjectCommon.close()
we drop the reference to the wrapped object.I can think of two possible fixes.
self._io
reference inclose()
, instead set aself._closed = True
flag to be used in__getattr__()
, and addname
in_delegate_methods()
.FileObjectCommon.__init__()
doself.name = self._io.name
.Thoughts?
What I've run:
The text was updated successfully, but these errors were encountered: