SimpleXMLRPCServer Releasing Ports

Pat Notz pknotz at
Wed Oct 9 15:24:13 CEST 2002

John Abel <john.abel at> wrote in message news:<mailman.1034078772.26126.python-list at>...
> Hi,
> I have a script running, using SimpleXMLRPCServer, which works OK. 
>  Except, when I stop, and restart the script, I receive the error, 
> "Address already in use".  Is there something I can do, like a 
> destructor, to tidy up, so that the script can be restarted?
> Thanks
> John

You're supposed to be able to set the .allow_reuse_address attribute
to True but there is a bug in the higher level SocketServer package
(which SimpleXMLRPCServer inherrits from).   We hit this same problem
with the SocketServer module and decided to write the whole server
from scratch using the low-level socket module (there were other
reasons for the re-write).

With low level sockets, you can do it like this,

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 2)

NOTE: The last argument is "2" not "1" and not "True".  This is the
bug in SocketServer -- the value is 1 which is wrong.  If you want,
you can go into the code and apply the fix -- just
search for allow_reuse_address and you'll see the setsockopt line. 
Change the last arg to 2 and you should be set.

HTH, Pat

More information about the Python-list mailing list