Skip to content

Instantly share code, notes, and snippets.

@schipiga
Last active November 22, 2019 19:09
Show Gist options
  • Save schipiga/3518930155560074284bad7583fc028e to your computer and use it in GitHub Desktop.
Save schipiga/3518930155560074284bad7583fc028e to your computer and use it in GitHub Desktop.
def setblocking():
setblocking_func = socket.socket.setblocking
def wrapper(self, flag):
if flag:
# prohibit timeout reset
timeout = socket.getdefaulttimeout()
if timeout:
self.settimeout(timeout)
else:
setblocking_func(self, flag)
else:
setblocking_func(self, flag)
wrapper.__doc__ = setblocking_func.__doc__
wrapper.__name__ = setblocking_func.__name__
return wrapper
socket.socket.setblocking = setblocking()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment