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.
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 75481dd..00a6396 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -614,6 +614,11 @@
         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 @@
         write = send
 
         def close(self):
+            if self.fd < 0:
+                return
             os.close(self.fd)
+            self.fd = -1
 
         def fileno(self):
             return self.fd