如何在容器中与Gunicorn一起运行的烧瓶应用程序?

发布于 2025-02-14 01:47:04 字数 276 浏览 4 评论 0原文

我一直在寻找一种启动Python调试器的方法,以便我可以调试烧瓶应用程序,该应用程序在Docker容器中被Gunicorn执行,然后从外部与我的Vscode连接。

但是我找不到任何解决方案。实际上,某人在这里表明根本不可能吗?

有没有办法调试由枪支执行的烧瓶应用程序?

I have been looking for a way to start a python debugger so I can debug my flask app which is being executed with gunicorn inside a docker container and then connect to it with my VSCode from outside.

But I dont find any solutions. In fact someone here suggests that it is not possible at all?

Is there a way to debug my flask app executed by gunicorn?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

俯瞰星空 2025-02-21 01:47:04

因此,与枪支有关,看起来这是非常困难的,即使不是不可能的ATM。因此,我所做的是

  1. 在我的项目中使用以下方式创建degub_app.py文件
 来自myApp.api导入create_app


如果__名称__ ==“ __ main__”:
    app = create_app()
    app.run('0.0.0.0',8000,debug = false)
 
  1. 我创建了一个调试容器,该容器在我的docker-compose file:
  api-debug:
        图片:“ MyApp:最新”
        重新启动:实施:3
        环境:
        卷:
           -  ./:/usr/src/app
        依赖_on:
           - 兔子
           -  redis
           - 蒙哥
        TTY:是的
        stdin_open:是的
        命令:尾巴-f任何东西
        端口:
          -8000:8000
 
  1. 然后将VSCODE远程容器插件I连接到该容器上。这启动了一个新的VSCODE窗口,并向您显示容器内的文件。

Note 由于VScode现在已连接到我必须重新安装Python扩展程序的容器(您可以查找此功能,但是很容易,只需转到插件,然后重新安装到容器),

  1. 我创建了一个启动.json在容器中以运行我上面提到的degub_app.py

{
“版本”:“ 0.2.0”,
“配置”:[
{
“名称”:“ python:debug api”,
“ type”:“ python”,
“请求”:“启动”,
“程序”:“ $ {workspacefolder} my_path/debug_api.py”,
“控制台”:“ IntegratedTerminal”,
“ JustMyCode”:false
}
这是给
}

So it looks like this is very difficult, if not impossible atm, to do with gunicorn. So what I did was

  1. Create a degub_app.py file in my project with :
from myapp.api import create_app


if __name__=="__main__":
    app = create_app()
    app.run('0.0.0.0', 8000, debug=False)
  1. I created a debug container which runs nothing on start it just waiting idle like this in my docker-compose file:
 api-debug:
        image: "myapp:latest"
        restart: on-failure:3
        environment:
        volumes:
          - ./:/usr/src/app
        depends_on:
          - rabbitmq
          - redis
          - mongo
        tty: true
        stdin_open: true
        command: tail -F anything
        ports:
          - 8000:8000
  1. Then using VSCode with the Remote Container pluggin i attached to that container. This starts a new VSCode window and shows you the files inside the container.

Note Since the VSCode is now connected to the container I had to re-install the Python extension (you can look this up but it is easy just go to pluggins and re-install to container)

  1. I created a launch.json inside the container to run the degub_app.py that I mentioned above like this:

{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug API",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}my_path/debug_api.py",
"console": "integratedTerminal",
"justMyCode": false
}
]
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文