(Merge 3.4) Issue #11453: asyncore: emit a ResourceWarning when an unclosed

file_wrapper object is destroyed. The destructor now closes the file if needed.
The close() method can now be called twice: the second call does nothing.
This commit is contained in:
Victor Stinner 2014-06-27 23:57:19 +02:00
commit a81088ae12
3 changed files with 28 additions and 0 deletions

View file

@ -600,6 +600,11 @@ if os.name == 'posix':
def __init__(self, fd):
self.fd = os.dup(fd)
def __del__(self):
if self.fd >= 0:
warnings.warn("unclosed file %r" % self, ResourceWarning)
self.close()
def recv(self, *args):
return os.read(self.fd, *args)
@ -618,7 +623,10 @@ if os.name == 'posix':
write = send
def close(self):
if self.fd < 0:
return
os.close(self.fd)
self.fd = -1
def fileno(self):
return self.fd