For socket, use:

import socket

sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 5555))
sock.close()

For socketserver, use:

import socketserver

socketserver.TCPServer.allow_reuse_address = True
... do stuff ...