mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #10093: ResourceWarnings are now issued when files and sockets are
deallocated without explicit closing. These warnings are silenced by default, except in pydebug mode.
This commit is contained in:
parent
9cbdd75ec5
commit
e033e06db0
10 changed files with 189 additions and 25 deletions
|
@ -706,6 +706,23 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
def test_sendall_interrupted_with_timeout(self):
|
||||
self.check_sendall_interrupted(True)
|
||||
|
||||
def test_dealloc_warn(self):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
r = repr(sock)
|
||||
with self.assertWarns(ResourceWarning) as cm:
|
||||
sock = None
|
||||
support.gc_collect()
|
||||
self.assertIn(r, str(cm.warning.args[0]))
|
||||
# An open socket file object gets dereferenced after the socket
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
f = sock.makefile('rb')
|
||||
r = repr(sock)
|
||||
sock = None
|
||||
support.gc_collect()
|
||||
with self.assertWarns(ResourceWarning):
|
||||
f = None
|
||||
support.gc_collect()
|
||||
|
||||
|
||||
@unittest.skipUnless(thread, 'Threading required for this test.')
|
||||
class BasicTCPTest(SocketConnectedTest):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue