socket.socket()
creates a socket as a context manager, but it only calls close()
on exit processing. I want to add sock.shutdown(socket.SHUT_RDWR)
to it because if it has unread data pending, calling close()
only will cause the peer to get ECONNRESET
(which caused me several hours to figure it out), as explained here TCP : recv() getting ECONNRESET (also refer to socket.shutdown vs socket.close)
How do I do that?
BTW, is this a good idea(as I haven't seen others do this)?