From 1c4440204f410b2839a44e83ac38cf52eafaadaa Mon Sep 17 00:00:00 2001 From: Timofei <128279579+deadlovelll@users.noreply.github.com> Date: Wed, 15 Jul 2026 11:44:30 +0300 Subject: [PATCH 1/2] gh-150952: Fix incorrect sock_sendto docstring (#150953) --- Lib/asyncio/selector_events.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 492dfcb19dafe2..97cb6b76ac2e89 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -586,14 +586,10 @@ def _sock_sendall(self, fut, sock, view, pos): pos[0] = start async def sock_sendto(self, sock, data, address): - """Send data to the socket. + """Send a datagram from sock to address. - The socket must be connected to a remote socket. This method - continues to send data from data until either all data has been - sent or an error occurs. None is returned on success. On error, - an exception is raised, and there is no way to determine how much - data, if any, was successfully processed by the receiving end of - the connection. + The socket does not have to be connected. This method sends the + whole datagram in a single call. Return the number of bytes sent. """ base_events._check_ssl_socket(sock) if self._debug and sock.gettimeout() != 0: From 4f3be1b5777313fb36ff4bda7e4a4197c932c30e Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Wed, 15 Jul 2026 12:39:28 +0200 Subject: [PATCH 2/2] gh-150452: use PyMutex in socket module (#150453) --- Modules/socketmodule.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index ada4fda6571049..084c2dbcff066e 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1170,7 +1170,7 @@ new_sockobject(socket_state *state, SOCKET_T fd, int family, int type, /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ #if defined(USE_GETHOSTBYNAME_LOCK) -static PyThread_type_lock netdb_lock; +static PyMutex netdb_lock = {0}; #endif @@ -6219,7 +6219,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args) #endif #else /* not HAVE_GETHOSTBYNAME_R */ #ifdef USE_GETHOSTBYNAME_LOCK - PyThread_acquire_lock(netdb_lock, 1); + PyMutex_Lock(&netdb_lock); #endif _Py_COMP_DIAG_PUSH _Py_COMP_DIAG_IGNORE_DEPR_DECLS @@ -6235,7 +6235,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args) ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), sa->sa_family); #ifdef USE_GETHOSTBYNAME_LOCK - PyThread_release_lock(netdb_lock); + PyMutex_Unlock(&netdb_lock); #endif finally: PyMem_Free(name); @@ -6326,7 +6326,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args) #endif #else /* not HAVE_GETHOSTBYNAME_R */ #ifdef USE_GETHOSTBYNAME_LOCK - PyThread_acquire_lock(netdb_lock, 1); + PyMutex_Lock(&netdb_lock); #endif _Py_COMP_DIAG_PUSH _Py_COMP_DIAG_IGNORE_DEPR_DECLS @@ -6336,7 +6336,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args) Py_END_ALLOW_THREADS ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af); #ifdef USE_GETHOSTBYNAME_LOCK - PyThread_release_lock(netdb_lock); + PyMutex_Unlock(&netdb_lock); #endif finally: PyMem_Free(ip_num); @@ -9292,15 +9292,6 @@ socket_exec(PyObject *m) #endif #endif /* _MSTCPIP_ */ - /* Initialize gethostbyname lock */ -#if defined(USE_GETHOSTBYNAME_LOCK) - netdb_lock = PyThread_allocate_lock(); - if (netdb_lock == NULL) { - PyErr_NoMemory(); - goto error; - } -#endif - #ifdef MS_WINDOWS /* remove some flags on older version Windows during run-time */ if (remove_unusable_flags(m) < 0) {