[issue11453] asyncore.file_wrapper should implement __del__ and call close there to prevent resource leaks and behave like socket.socket does.

Aldona Majorek report at bugs.python.org
Wed Jun 1 22:23:48 CEST 2011


Aldona Majorek <amajorek at google.com> added the comment:

Adding __exit__ will not make asyncore.file_wrapper close file descriptor when garbage collected.

Here is clone of socket.py solution for the same problem.

  def close(self):
    if self.fd:
      os.close(self.fd)
      self.fd = None # or maybe self.fd = 0 will be better

  def __del__(self):
    try:
      self.close()
    except:
      # close() may fail if __init__ didn't complete
      pass

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11453>
_______________________________________


More information about the Python-bugs-list mailing list