mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
252d40ef1e
commit
4d4c69dc35
3 changed files with 28 additions and 0 deletions
|
@ -436,6 +436,22 @@ class FileWrapperTest(unittest.TestCase):
|
|||
asyncore.loop(timeout=0.01, use_poll=True, count=2)
|
||||
self.assertEqual(b"".join(data), self.d)
|
||||
|
||||
def test_resource_warning(self):
|
||||
# Issue #11453
|
||||
fd = os.open(support.TESTFN, os.O_RDONLY)
|
||||
f = asyncore.file_wrapper(fd)
|
||||
with support.check_warnings(('', ResourceWarning)):
|
||||
f = None
|
||||
support.gc_collect()
|
||||
|
||||
def test_close_twice(self):
|
||||
fd = os.open(support.TESTFN, os.O_RDONLY)
|
||||
f = asyncore.file_wrapper(fd)
|
||||
f.close()
|
||||
self.assertEqual(f.fd, -1)
|
||||
# calling close twice should not fail
|
||||
f.close()
|
||||
|
||||
|
||||
class BaseTestHandler(asyncore.dispatcher):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue