You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add TCP keepalive option for asyncio.start_server() #101336
By default, this asyncio.start_server() method will create a list of socket objects usually for both IPv4 and IPv6 (if possible) and do not set keepalive option. if I want I can create a socket object by myself and set keepalive option for it, then pass it in start_server(), but if so, I will not be able to start a server which listens on both IPv4 and IPv6 addresses.
I hope we can add a keepalive parameter for asyncio.start_server() or do something else to make things easier.
I don't have the same problem as you, but I understand your problem. It is a recurrent problem for me. For many projects, not only web servers, but others TCP servers too. The same problem appears with others programming languages. To alleviate this problem in Python, I thought about monkey-patching the library in question, or the socket library to use TCP keepalive. The mode being applied before bind and connect. Can TCP keepalive be applied after bind, connect or the first interaction ? In addition to this, it is difficult to access the internal sockets.
For some software prototypes, (never in production), I patched some methods of the socket object to add TCP keepalive, for most OSes :
Activity
axoroll7 commentedon Aug 15, 2023
I don't have the same problem as you, but I understand your problem. It is a recurrent problem for me. For many projects, not only web servers, but others TCP servers too. The same problem appears with others programming languages. To alleviate this problem in Python, I thought about monkey-patching the library in question, or the socket library to use TCP keepalive. The mode being applied before
bindandconnect. Can TCP keepalive be applied afterbind,connector the first interaction ? In addition to this, it is difficult to access the internal sockets.For some software prototypes, (never in production), I patched some methods of the socket object to add TCP keepalive, for most OSes :
Function signature :
For linux :
For BSD (macOS, FreeBSD, OpenBSD, NetBSD) :
For Windows :
(English isn't my first language, so please excuse any mistakes.)
beavailable commentedon Aug 15, 2023
Seems that it can't.
gvanrossum commentedon Nov 27, 2023
Please just propose a pull request that adds a keyword parameter to the right API. We will take it from there.
gh-101336: Add keep_alive keyword arg for asyncio create_server() (#1…
pythongh-101336: Add keep_alive keyword arg for asyncio create_server…
pythongh-101336: Add keep_alive keyword arg for asyncio create_server…