classification
Title: socket._fileobject: read raises AttributeError when closed in another thread
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: panzi
Priority: normal Keywords:

Created on 2010-07-05 01:21 by panzi, last changed 2010-07-05 01:21 by panzi.

Files
File name Uploaded Description Edit
FileObject.py panzi, 2010-07-05 01:21 bugfix by subtyping socket._fileobject and overriding close and closed
Messages (1)
msg109281 - (view) Author: Mathias Panzenböck (panzi) Date: 2010-07-05 01:21
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.
History
Date User Action Args
2010-07-05 01:21:33panzicreate