我试图从mac终端设置一个带有python的服务器。
我导航到文件夹位置使用:
python -m SimpleHTTPServer但这给我错误:
socket.error: [Errno 48] Address already in use以前我已经使用相同的命令为我的机器中不同位置的不同网站打开了一个连接。
I'm trying to set up a server with python from mac terminal.
I navigate to folder location an use:
python -m SimpleHTTPServerBut this gives me error:
socket.error: [Errno 48] Address already in useI had previously open a connection using the same command for a different website in a different location in my machine.
最满意答案
您已经有一个流程绑定到默认端口(8000)。 如果您之前已经运行过相同的模块,则很可能该进程仍然绑定到端口。 首先尝试找到另一个进程:
$ ps -fA | grep python 501 81651 12648 0 9:53PM ttys000 0:00.16 python -m SimpleHTTPServer包含命令参数,因此如果多个python进程处于活动状态,您可以查看运行SimpleHTTPServer参数。 您可能想测试http://localhost:8000/仍然显示本地文件的目录列表。
第二个数字是过程编号; 通过发送信号来停止服务器:
kill 81651这发送标准SIGTERM信号; 如果进程无响应,则可能需要采取更严格的方法,例如发送SIGKILL ( kill -s KILL <pid>或kill -9 <pid> )信号。 更多详情请参阅维基百科 。
或者,通过在命令行中指定备用端口,在另一个端口上运行服务器:
$ python -m SimpleHTTPServer 8910 Serving HTTP on 0.0.0.0 port 8910 ...然后访问服务器http://localhost:8910 ; 其中8910可以是从1024及以上的任何数字,只要端口尚未被占用。
You already have a process bound to the default port (8000). If you already ran the same module before, it is most likely that process still bound to the port. Try and locate the other process first:
$ ps -fA | grep python 501 81651 12648 0 9:53PM ttys000 0:00.16 python -m SimpleHTTPServerThe command arguments are included, so you can spot the one running SimpleHTTPServer if more than one python process is active. You may want to test if http://localhost:8000/ still shows a directory listing for local files.
The second number is the process number; stop the server by sending it a signal:
kill 81651This sends a standard SIGTERM signal; if the process is unresponsive you may have to resort to tougher methods like sending a SIGKILL (kill -s KILL <pid> or kill -9 <pid>) signal instead. See Wikipedia for more details.
Alternatively, run the server on a different port, by specifying the alternative port on the command line:
$ python -m SimpleHTTPServer 8910 Serving HTTP on 0.0.0.0 port 8910 ...then access the server as http://localhost:8910; where 8910 can be any number from 1024 and up, provided the port is not already taken.
更多推荐
发布评论