Закрытие Python Good Good Way
from contextlib import closing
try:
with closing(sock):
sock.shutdown()
except OSError:
pass
Puzzled Puffin