classification
Title: asyncore file_wrapper leaking file descriptors?
Type: resource usage Stage: needs patch
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: giampaolo.rodola, keysers
Priority: normal Keywords:

Created on 2009-08-23 21:02 by keysers, last changed 2010-09-06 10:59 by giampaolo.rodola. This issue is now closed.

Messages (3)
msg91892 - (view) Author: Daniel Keysers (keysers) Date: 2009-08-23 21:02
I'm not very experienced in Python, but while tracking down an issue 
with a "too many open files" error I think I found a missing resource 
release in asyncore's file_wrapper. Since Rev. 64062 added the os.dup() 
in __init__ this class reads as follows:

if os.name == 'posix':
    import fcntl

    class file_wrapper:
        # Here we override just enough to make a file
        # look like a socket for the purposes of asyncore.
        # The passed fd is automatically os.dup()'d

        def __init__(self, fd):
            self.fd = os.dup(fd)

        def recv(self, *args):
            return os.read(self.fd, *args)

        def send(self, *args):
            return os.write(self.fd, *args)

        read = recv
        write = send

        def close(self):
            os.close(self.fd)

        def fileno(self):
            return self.fd


I think that a "def __del__(self): self.close()" or a variant thereof 
would solve the problem I was seeing since it would release the file 
descriptor acquired in __init__ by os.dup(). But since I don't know why 
the os.dup() was added in the first place I'm not sure if there aren't 
any arguments against this release. Any comment appreciated!
msg104044 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-04-23 20:21
I'm not sure how to reproduce this issue but I doubt calling close() from __del__ would solve the problem, neither would be a good idea as close() might end up being called more than once, which is not desirable.

Try to paste the code you're using: the problem might be that your application is not calling close() for some reason.
msg115696 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-09-06 10:59
Closing out because no response has been provided by the OP.
History
Date User Action Args
2010-09-06 10:59:00giampaolo.rodolasetstatus: open -> closed
resolution: wont fix
messages: + msg115696
2010-09-04 23:21:52pitrousetassignee: giampaolo.rodola
stage: needs patch
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2010-04-23 20:21:56giampaolo.rodolasetmessages: + msg104044
2010-03-14 22:27:53giampaolo.rodolasetnosy: + giampaolo.rodola
2009-08-23 21:02:30keyserscreate