summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2024-03-12 00:31:49 (GMT)
committerGitHub <noreply@github.com>2024-03-12 00:31:49 (GMT)
commitba13215eb1ec20b6af10e3fcee7a725bd7a7f83e (patch)
tree19615f6a1d8d22a9fe494bcfbf2cfe5bb50bf1e9 /Lib/asyncio/base_events.py
parent2b67fc57f6e97c8389fe970ed232c1ad484113e1 (diff)
downloadcpython-ba13215eb1ec20b6af10e3fcee7a725bd7a7f83e.zip
cpython-ba13215eb1ec20b6af10e3fcee7a725bd7a7f83e.tar.gz
cpython-ba13215eb1ec20b6af10e3fcee7a725bd7a7f83e.tar.bz2
gh-113538: Revert "gh-113538: Add asycio.Server.{close,abort}_clients (#114432)" (#116632)
Revert "gh-113538: Add asycio.Server.{close,abort}_clients (#114432)" Reason: The new test doesn't always pass: https://github.com/python/cpython/pull/116423#issuecomment-1989425489 This reverts commit 1d0d49a7e86257ff95b4de0685e6997d7533993c.
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py25
1 files changed, 8 insertions, 17 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index f0e690b..6c5cf28 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -279,9 +279,7 @@ class Server(events.AbstractServer):
ssl_handshake_timeout, ssl_shutdown_timeout=None):
self._loop = loop
self._sockets = sockets
- # Weak references so we don't break Transport's ability to
- # detect abandoned transports
- self._clients = weakref.WeakSet()
+ self._active_count = 0
self._waiters = []
self._protocol_factory = protocol_factory
self._backlog = backlog
@@ -294,13 +292,14 @@ class Server(events.AbstractServer):
def __repr__(self):
return f'<{self.__class__.__name__} sockets={self.sockets!r}>'
- def _attach(self, transport):
+ def _attach(self):
assert self._sockets is not None
- self._clients.add(transport)
+ self._active_count += 1
- def _detach(self, transport):
- self._clients.discard(transport)
- if len(self._clients) == 0 and self._sockets is None:
+ def _detach(self):
+ assert self._active_count > 0
+ self._active_count -= 1
+ if self._active_count == 0 and self._sockets is None:
self._wakeup()
def _wakeup(self):
@@ -349,17 +348,9 @@ class Server(events.AbstractServer):
self._serving_forever_fut.cancel()
self._serving_forever_fut = None
- if len(self._clients) == 0:
+ if self._active_count == 0:
self._wakeup()
- def close_clients(self):
- for transport in self._clients.copy():
- transport.close()
-
- def abort_clients(self):
- for transport in self._clients.copy():
- transport.abort()
-
async def start_serving(self):
self._start_serving()
# Skip one loop iteration so that all 'loop.add_reader'