Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36f7b97

Browse files
committed
remove __del__ because it's evil and also prevents the ResourceWarning on the socket from happening (closes #16900)
1 parent 7bd0486 commit 36f7b97

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/ssl.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,6 @@ def get_channel_binding(self, cb_type="tls-unique"):
574574
return None
575575
return self._sslobj.tls_unique_cb()
576576

577-
def __del__(self):
578-
# sys.stderr.write("__del__ on %s\n" % repr(self))
579-
self._real_close()
580-
581577

582578
def wrap_socket(sock, keyfile=None, certfile=None,
583579
server_side=False, cert_reqs=CERT_NONE,

Lib/test/test_ssl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ def test_tls_unique_channel_binding(self):
374374
ss = ssl.wrap_socket(s, server_side=True, certfile=CERTFILE)
375375
self.assertIsNone(ss.get_channel_binding("tls-unique"))
376376

377+
def test_dealloc_warn(self):
378+
ss = ssl.wrap_socket(socket.socket(socket.AF_INET))
379+
r = repr(ss)
380+
with self.assertWarns(ResourceWarning) as cm:
381+
ss = None
382+
support.gc_collect()
383+
self.assertIn(r, str(cm.warning.args[0]))
384+
377385
class ContextTests(unittest.TestCase):
378386

379387
@skip_if_broken_ubuntu_ssl

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ Core and Builtins
142142
Library
143143
-------
144144

145+
- Issue #16900: Issue a ResourceWarning when an ssl socket is left unclosed.
146+
145147
- Issue #15545: Fix regression in sqlite3's iterdump method where it was
146148
failing if the connection used a row factory (such as sqlite3.Row) that
147149
produced unsortable objects. (Regression was introduced by fix for 9750).

0 commit comments

Comments
 (0)