[Python-checkins] cpython (3.4): Issue #23209, #23225: selectors.BaseSelector.close() now clears its internal
victor.stinner
python-checkins at python.org
Tue Jan 13 10:01:58 CET 2015
https://hg.python.org/cpython/rev/1544bdc409be
changeset: 94120:1544bdc409be
branch: 3.4
parent: 94117:1b145e8ae4be
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jan 13 09:58:33 2015 +0100
summary:
Issue #23209, #23225: selectors.BaseSelector.close() now clears its internal
reference to the selector mapping to break a reference cycle. Initial patch
written by Martin Richard.
files:
Lib/selectors.py | 3 +++
Lib/test/test_selectors.py | 3 +++
Misc/NEWS | 4 ++++
3 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/Lib/selectors.py b/Lib/selectors.py
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -175,6 +175,8 @@
"""
mapping = self.get_map()
try:
+ if mapping is None:
+ raise KeyError
return mapping[fileobj]
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj)) from None
@@ -256,6 +258,7 @@
def close(self):
self._fd_to_key.clear()
+ self._map = None
def get_map(self):
return self._map
diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py
--- a/Lib/test/test_selectors.py
+++ b/Lib/test/test_selectors.py
@@ -180,6 +180,7 @@
s = self.SELECTOR()
self.addCleanup(s.close)
+ mapping = s.get_map()
rd, wr = self.make_socketpair()
s.register(rd, selectors.EVENT_READ)
@@ -188,6 +189,8 @@
s.close()
self.assertRaises(KeyError, s.get_key, rd)
self.assertRaises(KeyError, s.get_key, wr)
+ self.assertRaises(KeyError, mapping.__getitem__, rd)
+ self.assertRaises(KeyError, mapping.__getitem__, wr)
def test_get_key(self):
s = self.SELECTOR()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,10 @@
Library
-------
+- Issue #23209, #23225: selectors.BaseSelector.close() now clears its internal
+ reference to the selector mapping to break a reference cycle. Initial patch
+ written by Martin Richard.
+
- Issue #21356: Make ssl.RAND_egd() optional to support LibreSSL. The
availability of the function is checked during the compilation. Patch written
by Bernard Spil.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list