[New-bugs-announce] [issue9156] socket._fileobject: read raises AttributeError when closed in another thread
report at bugs.python.org
Mon Jul 5 03:21:35 CEST 2010
New submission from Mathias Panzenböck <grosser.meister.morti at gmx.net>:
When you open a socket._fileobject through sock.makefile('rb') or similar and you read blocking in one thread and close the file object from another thread the reading thread gets an AttributeError. This is because the close method sets the underlying fileobject._sock member to None and the read/readline/... methods call recv on this member without checking if its None. I think the _sock member should not be set to None at all but a flag should be set that this file object is closed.
For the time being I use the "bugfix" I attached and therefore do not call sock.makefile('rb') but FileObject(sock, 'rb'). FileObject is a subtype of socket._fileobject that overrides the close method and closed property.
I don't know if this bug persists in 2.7 or 3.x. I still use Fedora 12 and that comes with Python 2.6.2.
components: Library (Lib)
title: socket._fileobject: read raises AttributeError when closed in another thread
versions: Python 2.6
Added file: http://bugs.python.org/file17860/FileObject.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce