【问题标题】:Port XXXX is in use by another program. Either identify and stop that program, or start the server with a different port端口 XXXX 正被另一个程序使用。识别并停止该程序,或使用不同的端口启动服务器
【发布时间】:2022-11-05 20:26:38
【问题描述】:

我想运行一个 python flask hello world。我部署到 App Engine,但它显示的好像是说端口正在使用中,并且看起来它同时在多个实例/线程/克隆上运行。

这是我的 main.py

from flask import Flask

app = Flask(__name__)

@app.route('/hello')
def helloIndex():
    print("Hello world log console")
    return 'Hello World from Python Flask!'
      
app.run(host='0.0.0.0', port=4444)

这是我的 app.yaml

runtime: python38
env: standard
instance_class: B2
handlers:
  - url: /
    script: auto
  - url: .*
    script: auto
manual_scaling:
  instances: 1

这是我的要求.txt

gunicorn==20.1.0
flask==2.2.2

这是我得到的日志:

* Serving Flask app 'main'
* Debug mode: off
Address already in use
Port 4444 is in use by another program. Either identify and stop that program, or start the server with a different port.
[2022-08-10 15:57:28 +0000] [1058] [INFO] Worker exiting (pid: 1058)
[2022-08-10 15:57:29 +0000] [1059] [INFO] Booting worker with pid: 1059
[2022-08-10 15:57:29 +0000] [1060] [INFO] Booting worker with pid: 1060
[2022-08-10 15:57:29 +0000] [1061] [INFO] Booting worker with pid: 1061

它说端口 4444 正在使用中。最初我尝试了 5000(flask 的默认端口),但它说它正在使用中。我也尝试删除port=4444,但现在它说Port 5000 is in use by another program,我猜烧瓶默认分配端口= 5000。我怀疑这是因为 GAE 在多个实例中运行导致此错误。如果没有,那么请帮助解决这个问题。

【问题讨论】:

标签: google-app-engine google-app-engine-python


【解决方案1】:

App Engine 应用应侦听端口 8080,而不是任何其他端口。

所以你可能需要像这样设置

app.run(host='0.0.0.0', port=8080)

【讨论】:

  • 现在它说Port 8080 is in use by another program. Either identify and stop that program, or start the server with a different port.....请帮助...
【解决方案2】:

我想到了。从您的终端和/或创建 Web 应用程序的文件夹中删除您的旧文件。在终端中,这是通过以下方式完成的:

rm -file_name

然后用你的新文件重新尝试,应该没问题。

【讨论】:

    【解决方案3】:

    关闭编辑器,然后重新打开。下次停止进程时,如果您在终端上,请使用 Ctrl+C

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-30
      • 2015-08-12
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      相关资源
      最近更新 更多