Skip to content

Commit 94d16d2

Browse files
authored
gh-89977: Keep the GIL for short socket calls (#157981)
1 parent eaab974 commit 94d16d2

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Avoid releasing the GIL for :meth:`socket.socket.setblocking`,
2+
:meth:`socket.socket.getsockname`, :meth:`socket.socket.getpeername`, and
3+
:func:`socket.gethostname`.

‎Modules/socketmodule.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ internal_setblocking(PySocketSockObject *s, int block)
832832
int delay_flag, new_delay_flag;
833833
#endif
834834

835-
Py_BEGIN_ALLOW_THREADS
836835
#ifndef MS_WINDOWS
837836
#if (defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO))
838837
block = !block;
@@ -859,8 +858,6 @@ internal_setblocking(PySocketSockObject *s, int block)
859858
result = 0;
860859

861860
done:
862-
Py_END_ALLOW_THREADS
863-
864861
if (result) {
865862
#ifndef MS_WINDOWS
866863
PyErr_SetFromErrno(PyExc_OSError);
@@ -3917,9 +3914,7 @@ _socket_socket_getsockname_impl(PySocketSockObject *s)
39173914
if (!getsockaddrlen(s, &addrlen))
39183915
return NULL;
39193916
memset(&addrbuf, 0, addrlen);
3920-
Py_BEGIN_ALLOW_THREADS
39213917
res = getsockname(get_sock_fd(s), SAS2SA(&addrbuf), &addrlen);
3922-
Py_END_ALLOW_THREADS
39233918
if (res < 0)
39243919
return s->errorhandler();
39253920
return makesockaddr(get_sock_fd(s), SAS2SA(&addrbuf), addrlen,
@@ -3952,9 +3947,7 @@ _socket_socket_getpeername_impl(PySocketSockObject *s)
39523947
if (!getsockaddrlen(s, &addrlen))
39533948
return NULL;
39543949
memset(&addrbuf, 0, addrlen);
3955-
Py_BEGIN_ALLOW_THREADS
39563950
res = getpeername(get_sock_fd(s), SAS2SA(&addrbuf), &addrlen);
3957-
Py_END_ALLOW_THREADS
39583951
if (res < 0)
39593952
return s->errorhandler();
39603953
return makesockaddr(get_sock_fd(s), SAS2SA(&addrbuf), addrlen,
@@ -5970,9 +5963,7 @@ _socket_gethostname_impl(PyObject *module)
59705963
#else
59715964
char buf[1024];
59725965
int res;
5973-
Py_BEGIN_ALLOW_THREADS
59745966
res = gethostname(buf, (int) sizeof buf - 1);
5975-
Py_END_ALLOW_THREADS
59765967
if (res < 0)
59775968
return set_error();
59785969
buf[sizeof buf - 1] = '\0';

0 commit comments

Comments
 (0)