Attached patch avoids a syscall on socket.setblocking() and socket.settimeout() when possible: use ioctl(FIONBIO) when available (not only on VMS), or use fcntl() but only call fcntl() twice if the flags changed. The fcntl() optimization was suggested by Peter Portante some months ago: https://mail.python.org/pipermail/python-dev/2013-January/123661.html See also the rejected issue #19813: "Add a new optional timeout parameter to socket.socket() constructor".