'Unable to debug PyCharm Remote Python scripts (docker-compose)

Using: PyCharm 2021.3.2 (Professional Edition)

Situation: -

  • I have a docker-compose.yml based deployment
  • It contains one image that's deployed with a different behaviour based on environment variables

What I'm finding is that the built-in Remote Python debugging works when the image runs using unicorn (i.e. I can set breakpoints and pause the program) but I cannot debug python code that exists in the same image (i.e. I cannot set breakpoints or pause the program).

I'm using separate Python Interpreters for each service in the docker-compose file, as recommended. Each service uses the same image, controlled by variations in the environment variables. I have an interpreter for the unicorn app in the docker-compose file, another for the Python script.

Summary of the unicorn run-config

  • Script path: /usr/local/bin/gunicorn
  • Parameters: app.app:app

This runs, as expected, and can be debugged (i.e. I can set breakpoints and pause the app).

Summary of the python script/module config

This is the same image, but instead of running gunicorn with arguments I'm just running some python that's in the image.

  • Script path: test.py
  • Parameters:

I can launch the app in its container and see the container logs. But, unlike the gunicorn run-config above, the debugging is not working. In this container image I cannot set breakpoints or pause the image execution.

I've tried everything but it just feels that scripts/modules can't be debugged in my image whereas gunicorn can be debugged. I have other containers that run flask and celerly as the main program and they too can be debugged. But my attempts at debugging 'raw' Python scripts all fail.

This is the latest PyCharm pro and I am perplexed as to why the image can be debugged when running gunicorn but not when running a python script.

Has anyone else encountered this?

What Aam I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source