diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 705e4068130..03d16838b73 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -619,8 +619,9 @@ if os.name == 'posix': def close(self): if self.fd < 0: return - os.close(self.fd) + fd = self.fd self.fd = -1 + os.close(fd) def fileno(self): return self.fd diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index dc2f716e0bb..07edf2275be 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -433,7 +433,10 @@ class FileWrapperTest(unittest.TestCase): f = asyncore.file_wrapper(fd) os.close(fd) - f.close() + os.close(f.fd) # file_wrapper dupped fd + with self.assertRaises(OSError): + f.close() + self.assertEqual(f.fd, -1) # calling close twice should not fail f.close()