Skip to content

Commit 7491e7f

Browse files
committed
added docs entry
1 parent b0d61d2 commit 7491e7f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Doc/library/socket.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,24 @@ Socket Objects
20942094

20952095
For further information, please consult the :ref:`notes on socket timeouts <socket-timeouts>`.
20962096

2097+
.. note::
2098+
2099+
Do not call :meth:`setblocking` or :meth:`settimeout` while another
2100+
thread is performing an operation on the same socket. Changing the
2101+
blocking mode concurrently with operations such as :meth:`connect`,
2102+
:meth:`accept`, :meth:`recv`, or :meth:`send` can cause the operation
2103+
to block unexpectedly or to fail with a non-blocking error.
2104+
2105+
Applications must use external synchronization when changing a
2106+
socket's blocking mode or timeout. This also applies to socket
2107+
objects and file descriptors that share the same underlying socket,
2108+
since the blocking mode is shared at the operating-system level.
2109+
2110+
Reading a socket's current timeout or blocking mode with
2111+
:meth:`gettimeout` or :meth:`getblocking` remains safe to do
2112+
concurrently, only *changing* it during an operation requires the
2113+
synchronization described above.
2114+
20972115
.. versionchanged:: 3.7
20982116
The method no longer toggles :const:`SOCK_NONBLOCK` flag on
20992117
:attr:`socket.type`.

0 commit comments

Comments
 (0)