在 docker-compose 上启动 Django 服务器时,Pycharm 调试不会在断点处停止

问题描述 投票:0回答:1

我有一个 Django 项目,当我通过 CLI 在我的机器上运行时,我可以完美地调试它,但是当我将逻辑移到 Docker 和 docker-compose 中时,即使它运行时没有任何问题,我也无法再调试它,即它确实不会在断点处停止,即使我可以通过调试器控制台看到 Pydevd 接收与添加/删除断点相关的命令:

/usr/local/bin/python3 /opt/.pycharm_helpers/pydev/pydevd.py --multiprocess --client host.docker.internal --port 55583 --file /opt/project/manage.py runserver 0.0.0.0:8000 
Container project-api-db-1  Running
Container project-api-project-api-1  Recreate
Container project-api-project-api-1  Recreated
Attaching to project-api-project-api-1
project-api-project-api-1  | Executing PyCharm's `sitecustomize`
project-api-project-api-1  | User doesn't have a custom `sitecustomize`
project-api-project-api-1  | Custom matplotlib backend was set for SciView
project-api-project-api-1  | Debugger warning: It seems that frozen modules are being used, which may
project-api-project-api-1  | make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
project-api-project-api-1  | to python to disable frozen modules.
project-api-project-api-1  | Note: Debugging will proceed.
project-api-project-api-1  | Unable to load jupyter_debug plugin
project-api-project-api-1  | Executing file /opt/project/manage.py
project-api-project-api-1  | arguments: ['/opt/project/manage.py', 'runserver', '0.0.0.0:8000']
project-api-project-api-1  | PYDEVD_FILTER_LIBRARIES False
project-api-project-api-1  | 
project-api-project-api-1  | ('Connecting to ', 'host.docker.internal', ':', '55583')
project-api-project-api-1  | ('Connected.',)
project-api-project-api-1  | debugger: received >>501   1   0.1 UNIX
project-api-project-api-1  | <<
project-api-project-api-1  | Received command: CMD_VERSION 501  1   0.1 UNIX
Connected to pydev debugger (build 231.9225.15)
project-api-project-api-1  | 
project-api-project-api-1  | sending cmd -->          CMD_VERSION @@BUILD_NUMBER@@
project-api-project-api-1  | debugger: received >>111   3   python-line /opt/project/screenshots/schemas/screenshot.py  37  mutate  THREAD  None    None
project-api-project-api-1  | 101    9   
project-api-project-api-1  | 146    11  SHOW_RETURN_VALUES  0
project-api-project-api-1  | 111    5   python-line /opt/project/screenshots/views.py   5   index   THREAD  None    None
project-api-project-api-1  | 111    7   python-line /opt/project/screenshots/schemas/screenshot.py  43  mutate  THREAD  None    None
project-api-project-api-1  | <<
project-api-project-api-1  | Received command: CMD_SET_BREAK 111    3   python-line /opt/project/screenshots/schemas/screenshot.py  37  mutate  THREAD  None    None
project-api-project-api-1  | 
project-api-project-api-1  | Added breakpoint:/opt/project/screenshots/schemas/screenshot.py - line:37 - func_name:b'mutate'
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_RUN 101  9   
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_SHOW_RETURN_VALUES 146   11  SHOW_RETURN_VALUES  0
project-api-project-api-1  | 
project-api-project-api-1  | Show return values: False
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_SET_BREAK 111    5   python-line /opt/project/screenshots/views.py   5   index   THREAD  None    None
project-api-project-api-1  | 
project-api-project-api-1  | Added breakpoint:/opt/project/screenshots/views.py - line:5 - func_name:b'index'
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_SET_BREAK 111    7   python-line /opt/project/screenshots/schemas/screenshot.py  43  mutate  THREAD  None    None
project-api-project-api-1  | 
project-api-project-api-1  | Added breakpoint:/opt/project/screenshots/schemas/screenshot.py - line:43 - func_name:b'mutate'
project-api-project-api-1  | 
project-api-project-api-1  | sending cmd -->    CMD_THREAD_CREATE <xml><thread name="MainThread" id="pid_1_id_281473140200016" /></xml>
project-api-project-api-1  | IDE_PROJECT_ROOTS ['/opt/project']
project-api-project-api-1  | 
project-api-project-api-1  | LIBRARY_ROOTS ['/Users/user/Library/Caches/JetBrains/PyCharm2023.1/remote_sources/-2013456723/-853142961', '/Users/user/Library/Caches/JetBrains/PyCharm2023.1/remote_sources/-2013456723/78907351', '/Users/user/Library/Caches/JetBrains/PyCharm2023.1/remote_sources/-2013456723/-727148301', '/Users/user/Library/Caches/JetBrains/PyCharm2023.1/python_stubs/1437855905', '/Applications/PyCharm.app/Contents/plugins/python/helpers/python-skeletons', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stdlib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/gdb', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/six', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/boto', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/mock', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pytz', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/toml', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/tqdm', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/annoy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/babel', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/emoji', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/first', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/fpdf2', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/ldap3', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/polib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/redis', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/regex', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/retry', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/ujson', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/bleach', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/caldav', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/docopt', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/hdbcli', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/invoke', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/passpy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Pillow', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/psutil', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pycurl', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pynput', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pysftp', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/PyYAML', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/stripe', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/xxhash', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/zxcvbn', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/appdirs', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/certifi', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/chardet', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/chevron', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/passlib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyaudio', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/PyMySQL', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyvmomi', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/slumber', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/tzlocal', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/urllib3', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/vobject', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/aiofiles', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/colorama', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/croniter', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/docutils', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/html5lib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/httplib2', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/jmespath', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Markdown', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/oauthlib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/openpyxl', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/paramiko', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/psycopg2', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyflakes', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Pygments', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/requests', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/selenium', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/tabulate', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/toposort', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/waitress', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/braintree', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/decorator', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/freezegun', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/playsound', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyOpenSSL', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyRFC3339', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/termcolor', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/ttkthemes', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/typed-ast', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/xmltodict', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/cachetools', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/commonmark', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/dateparser', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Deprecated', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Flask-Cors', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/jsonschema', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyfarmhash', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Send2Trash', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/setuptools', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/simplejson', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/SQLAlchemy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/contextvars', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/entrypoints', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-2020', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/JACK-Client', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/mysqlclient', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/opentracing', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pep8-naming', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/prettytable', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-jose', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-nmap', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/stdlib-list', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/atomicwrites', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/aws-xray-sdk', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/cryptography', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/editdistance', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/parsimonious', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/whatthepatch', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/click-spinner', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/DateTimeRange', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/humanfriendly', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-gflags', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/beautifulsoup4', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-bugbear', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-slugify', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/singledispatch', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/dj-database-url', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-builtins', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-simplify', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/mypy-extensions', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-dateutil', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Flask-SQLAlchemy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-docstrings', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-plugin-utils', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pytest-lazy-fixture', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-rst-docstrings', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-typing-imports', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/backports.ssl_match_hostname']
project-api-project-api-1  | 
project-api-project-api-1  | Executing PyCharm's `sitecustomize`
project-api-project-api-1  | User doesn't have a custom `sitecustomize`
project-api-project-api-1  | Custom matplotlib backend was set for SciView
project-api-project-api-1  | Watching for file changes with StatReloader
project-api-project-api-1  | Performing system checks...
project-api-project-api-1  | 
project-api-project-api-1  | System check identified no issues (0 silenced).
project-api-project-api-1  | July 14, 2023 - 18:52:12
project-api-project-api-1  | Django version 4.2.3, using settings 'project_api.settings'
project-api-project-api-1  | Starting development server at http://0.0.0.0:8000/
project-api-project-api-1  | Quit the server with CONTROL-C.
project-api-project-api-1  | 
project-api-project-api-1  | [14/Jul/2023 18:52:15] "GET / HTTP/1.1" 200 13
project-api-project-api-1  | [14/Jul/2023 18:52:19] "GET / HTTP/1.1" 200 13

docker-compose.yml:

version: "3.7"
services:
  db:
    image: postgres:13.11-bullseye
    restart: always
    env_file:
      - database.env
    networks:
      - backend
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
  skreenshottr-api:
    tty: true
    stdin_open: true
    build:
      context: .
      dockerfile: .docker/Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    networks:
      - backend
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    env_file:
      - .env
    depends_on:
      - db

networks:
  backend:
    name: backend
    external: true

volumes:
  postgres_data:
    driver: local

这是我的 Python 解释器配置以及 Django 服务器运行/调试配置:

代码的工作方式就像一个魅力,但永远不会在断点处停止,即使在不使用 Docker 的情况下手动启动 Django 时,它也会在断点处停止。重新启动 PyCharm/计算机、更新 PyCharm、删除 .idea 文件夹或使缓存无效也不起作用。

编辑:

  • PyCharm 版本:2023.1.4
  • 专业Python版本:3.11.4
  • Docker 版本:20.10.23
django debugging docker-compose pycharm
1个回答
0
投票

Docker 在其容器中重新创建所有内容,因此您将无法使用标准调试工具访问它。但是可以使用

pdb
进行交互式调试。请参阅此答案

© www.soinside.com 2019 - 2024. All rights reserved.