Python [Errno 98] Address already in use

前端 未结 9 2613
一个人的身影
一个人的身影 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 10:44

    Yes, it is intended. Here you can read detailed explanation. It is possible to override this behavior by setting SO_REUSEADDR option on a socket. For example:

    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    
    0 讨论(0)
  • 2020-11-27 10:47

    Got the same error :
    Steps followed :
    1 - used $ ps -fA | grep python
    2 - Killed all the process
    3 - Closed terminal
    4 - relaunced and launched the application ( mkchromecast).
    5 - did not get this error message.

    Got another issue. following up on that .

    0 讨论(0)
  • 2020-11-27 10:48

    because you trying to run service in same port that is already running.

    some time its happen because your service is not stopped in process stack. you have to kill them

    no need to install anything here is the one line command to kill all running python processes.

    for Linux based OS:

    Bash:

    kill -9 $(ps -A | grep python | awk '{print $1}')
    

    Fish:

    kill -9 (ps -A | grep python | awk '{print $1}')
    
    0 讨论(0)
  • 2020-11-27 10:49

    run the command

    fuser -k (port_number_you_are _trying_to_access)/TCP
    

    example for flask: fuser -k 5000/tcp

    Also, remember this error arises when you interput by ctrl+z. so to terminate use ctrl+c

    0 讨论(0)
  • 2020-11-27 10:50

    First of all find the python process ID using this command

    ps -fA | grep python
    

    You will get a pid number by naming of your python process on second column

    Then kill the process using this command

    kill -9 pid
    
    0 讨论(0)
  • 2020-11-27 10:53

    Nothing worked for me except running a subprocess with this command, before calling HTTPServer(('', 443), myHandler):

    kill -9 $(lsof -ti tcp:443)
    

    Of course this is only for linux-like OS!

    0 讨论(0)
提交回复
热议问题