Python使用socket通信,在关闭终端后,再次启动脚本会出现如下问题:
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
Traceback (most recent call last):
File "socket_py_multi_process.py", line 378, in <module>
socketInstance.bind(ip_port)
OSError: [Errno 98] Address already in use
解决办法:
1. 先确认使用的进程:
ps -aux | grep socket_py_xxx.py
2. 杀掉进程:
kill -9 23162
3. 此时再次启动脚本还是会出现上述错误,这时候确认使用的端口,本人使用的端口是8089:
netstat -tlnp | grep 8089
tcp 0 0 127.0.0.1:8089 0.0.0.0:* LISTEN 23620/python
再次杀掉进程
kill -9 23620
4. 之后再次运行就正常了

本文详细介绍了在Python中使用socket通信时遇到的端口被占用问题及其解决步骤。当关闭终端再次启动脚本出现“Address already in use”错误时,通过查找并终止占用端口的进程可以有效解决问题。

2695

被折叠的 条评论
为什么被折叠?



