4

I'm trying to use threading socket server

self.server = SocketServer.ThreadingTCPServer( ( HOST, PORT ), MCRequestHandler )

and the destructor

def __del__( self ):
 self.server.shutdown();
 self.server.server_close()
 print( 'Server closed ! ' );

When I close the GUI the del function will be called, but if I want to start again the program, I get the following error message

socket.error: [Errno 98] Address already in use
Exception AttributeError: "'MCCommunication' object has no attribute 'server'" in <bound method MCCommunication.__del__ of <MCCommunication.MCCommunication object at 0x26867c0>> ignored
asked Jun 28, 2011 at 10:35

1 Answer 1

3

Make a subclass of TCPServer, and add this to it:

class TCPServer(SocketServer.TCPServer):
allow_reuse_address = True 

Basically the same as setsockopt, but, easier.

answered Jun 28, 2011 at 10:38
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.