[Python-checkins] Re-add `reuse_address` parameter to `create_server` (GH-29733)
asvetlov
webhook-mailer at python.org
Sun Dec 12 04:47:12 EST 2021
https://github.com/python/cpython/commit/f3c16a5e72aaf06bec863fa3a172f3deaa491bc9
commit: f3c16a5e72aaf06bec863fa3a172f3deaa491bc9
branch: main
author: Jim Crist-Harif <jcristharif at gmail.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2021-12-12T11:47:01+02:00
summary:
Re-add `reuse_address` parameter to `create_server` (GH-29733)
This parameter was accidentally removed when fixing
https://bugs.python.org/issue45129, this reverts the unnecessary changes
there.
Co-authored-by: Andrew Svetlov <andrew.svetlov at gmail.com>
files:
M Lib/asyncio/base_events.py
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index cfaf082587bb2..cbf6d5db0a002 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1394,6 +1394,7 @@ async def create_server(
sock=None,
backlog=100,
ssl=None,
+ reuse_address=None,
reuse_port=None,
ssl_handshake_timeout=None,
start_serving=True):
@@ -1424,6 +1425,8 @@ async def create_server(
raise ValueError(
'host/port and sock can not be specified at the same time')
+ if reuse_address is None:
+ reuse_address = os.name == "posix" and sys.platform != "cygwin"
sockets = []
if host == '':
hosts = [None]
@@ -1453,6 +1456,9 @@ async def create_server(
af, socktype, proto, exc_info=True)
continue
sockets.append(sock)
+ if reuse_address:
+ sock.setsockopt(
+ socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
if reuse_port:
_set_reuseport(sock)
# Disable IPv4/IPv6 dual stack support (enabled by
More information about the Python-checkins
mailing list