In my Python socket program, I sometimes need to interrupt it with Ctrl-C. When I do this, it does close the connection using socket.close().
socket.close()
Nothing worked for me except running a subprocess with this command, before calling HTTPServer(('', 443), myHandler):
HTTPServer(('', 443), myHandler)
kill -9 $(lsof -ti tcp:443)
Of course this is only for linux-like OS!