@contextmanager
def default_socket_timeout(timeout):
 prev = socket.getdefaulttimeout()
 socket.setdefaulttimeout(timeout)
 (yield)
 socket.setdefaulttimeout(prev)

@ contextmanager def default_socket_timeout ( timeout ) : prev = socket . getdefaulttimeout ( ) socket . setdefaulttimeout ( timeout ) ( yield ) socket . setdefaulttimeout ( prev )
context temporarily setting the default socket timeout .