Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2956310

Browse filesBrowse files
beavailablepull[bot]
authored andcommitted
gh-101336: Add keep_alive keyword arg for asyncio create_server() (#112485)
1 parent fcb6e80 commit 2956310
Copy full SHA for 2956310

File tree

Expand file treeCollapse file tree

4 files changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+17
-0
lines changed

‎Doc/library/asyncio-eventloop.rst

Copy file name to clipboardExpand all lines: Doc/library/asyncio-eventloop.rst
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ Creating network servers
671671
flags=socket.AI_PASSIVE, \
672672
sock=None, backlog=100, ssl=None, \
673673
reuse_address=None, reuse_port=None, \
674+
keep_alive=None, \
674675
ssl_handshake_timeout=None, \
675676
ssl_shutdown_timeout=None, \
676677
start_serving=True)
@@ -735,6 +736,13 @@ Creating network servers
735736
set this flag when being created. This option is not supported on
736737
Windows.
737738

739+
* *keep_alive* set to ``True`` keeps connections active by enabling the
740+
periodic transmission of messages.
741+
742+
.. versionchanged:: 3.13
743+
744+
Added the *keep_alive* parameter.
745+
738746
* *ssl_handshake_timeout* is (for a TLS server) the time in seconds to wait
739747
for the TLS handshake to complete before aborting the connection.
740748
``60.0`` seconds if ``None`` (default).

‎Lib/asyncio/base_events.py

Copy file name to clipboardExpand all lines: Lib/asyncio/base_events.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ async def create_server(
14961496
ssl=None,
14971497
reuse_address=None,
14981498
reuse_port=None,
1499+
keep_alive=None,
14991500
ssl_handshake_timeout=None,
15001501
ssl_shutdown_timeout=None,
15011502
start_serving=True):
@@ -1569,6 +1570,9 @@ async def create_server(
15691570
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
15701571
if reuse_port:
15711572
_set_reuseport(sock)
1573+
if keep_alive:
1574+
sock.setsockopt(
1575+
socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)
15721576
# Disable IPv4/IPv6 dual stack support (enabled by
15731577
# default on Linux) which makes a single socket
15741578
# listen on both address families.

‎Lib/asyncio/events.py

Copy file name to clipboardExpand all lines: Lib/asyncio/events.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ async def create_server(
316316
*, family=socket.AF_UNSPEC,
317317
flags=socket.AI_PASSIVE, sock=None, backlog=100,
318318
ssl=None, reuse_address=None, reuse_port=None,
319+
keep_alive=None,
319320
ssl_handshake_timeout=None,
320321
ssl_shutdown_timeout=None,
321322
start_serving=True):
@@ -354,6 +355,9 @@ async def create_server(
354355
they all set this flag when being created. This option is not
355356
supported on Windows.
356357
358+
keep_alive set to True keeps connections active by enabling the
359+
periodic transmission of messages.
360+
357361
ssl_handshake_timeout is the time in seconds that an SSL server
358362
will wait for completion of the SSL handshake before aborting the
359363
connection. Default is 60s.
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``keep_alive`` keyword parameter for :meth:`AbstractEventLoop.create_server` and :meth:`BaseEventLoop.create_server`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.