开发者

Python socketserver problem

开发者 https://www.devze.com 2023-03-16 01:45 出处:网络
I\'m trying to use threadi开发者_运维问答ng socket server self.server = SocketServer.ThreadingTCPServer( ( HOST, PORT ), MCRequestHandler )

I'm trying to use threadi开发者_运维问答ng 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消