Skip to content

Commit

Permalink
pythongh-101336: Add keep_alive keyword arg for asyncio create_server…
Browse files Browse the repository at this point in the history
  • Loading branch information
beavailable authored and Glyphack committed Jan 27, 2024
1 parent bfd9860 commit 8f330fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ Creating network servers
flags=socket.AI_PASSIVE, \
sock=None, backlog=100, ssl=None, \
reuse_address=None, reuse_port=None, \
keep_alive=None, \
ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None, \
start_serving=True)
Expand Down Expand Up @@ -735,6 +736,13 @@ Creating network servers
set this flag when being created. This option is not supported on
Windows.

* *keep_alive* set to ``True`` keeps connections active by enabling the
periodic transmission of messages.

.. versionchanged:: 3.13

Added the *keep_alive* parameter.

* *ssl_handshake_timeout* is (for a TLS server) the time in seconds to wait
for the TLS handshake to complete before aborting the connection.
``60.0`` seconds if ``None`` (default).
Expand Down
4 changes: 4 additions & 0 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,7 @@ async def create_server(
ssl=None,
reuse_address=None,
reuse_port=None,
keep_alive=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None,
start_serving=True):
Expand Down Expand Up @@ -1569,6 +1570,9 @@ async def create_server(
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
if reuse_port:
_set_reuseport(sock)
if keep_alive:
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)
# Disable IPv4/IPv6 dual stack support (enabled by
# default on Linux) which makes a single socket
# listen on both address families.
Expand Down
4 changes: 4 additions & 0 deletions Lib/asyncio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ async def create_server(
*, family=socket.AF_UNSPEC,
flags=socket.AI_PASSIVE, sock=None, backlog=100,
ssl=None, reuse_address=None, reuse_port=None,
keep_alive=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None,
start_serving=True):
Expand Down Expand Up @@ -354,6 +355,9 @@ async def create_server(
they all set this flag when being created. This option is not
supported on Windows.
keep_alive set to True keeps connections active by enabling the
periodic transmission of messages.
ssl_handshake_timeout is the time in seconds that an SSL server
will wait for completion of the SSL handshake before aborting the
connection. Default is 60s.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``keep_alive`` keyword parameter for :meth:`AbstractEventLoop.create_server` and :meth:`BaseEventLoop.create_server`.

0 comments on commit 8f330fd

Please sign in to comment.