Python [Errno 98] Address already in use

前端 未结 9 2607
一个人的身影
一个人的身影 2020-11-27 10:35

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().

相关标签:
9条回答
  • 2020-11-27 11:01
    $ ps -fA | grep python
    501 81211 12368   0  10:11PM ttys000    0:03.12  
    python -m SimpleHTTPServer
    
    $ kill 81211
    
    0 讨论(0)
  • 2020-11-27 11:02

    A simple solution that worked for me is to close the Terminal and restart it.

    0 讨论(0)
  • 2020-11-27 11:04

    If you use a TCPServer, UDPServer or their subclasses in the SocketServer module, you can set this class variable (before instanciating a server):

    SocketServer.TCPServer.allow_reuse_address = True
    

    (via SocketServer.ThreadingTCPServer - Cannot bind to address after program restart )

    This causes the init (constructor) to:

     if self.allow_reuse_address:
         self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    
    0 讨论(0)
提交回复
热议问题