summaryrefslogtreecommitdiff
path: root/Lib/asyncore.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-27 23:52:03 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-06-27 23:52:03 +0200
commit4d4c69dc35154a9c21fed1b6b4088e741fbc6ae6 (patch)
treef4ca0640823595c1beca048f262ee5035166ec14 /Lib/asyncore.py
parent252d40ef1ee627148ae12ab9cbf812cfeeb27655 (diff)
downloadcpython-git-4d4c69dc35154a9c21fed1b6b4088e741fbc6ae6.tar.gz
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.
Diffstat (limited to 'Lib/asyncore.py')
-rw-r--r--Lib/asyncore.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 75481ddde0..00a6396dd4 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -614,6 +614,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)
@@ -632,7 +637,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