title: Python: debugging and auto reload on docker container
body: <p>Mi situation is: I'm developing some docker containers. One of these containers is a celery app that get some tasks from another app and process these tasks.</p>
  <p>As I'm working everything in the containers I need to debug on the container and also I need some reloading of the app when the code changes.</p>
  <p>I can make both things to work separately using <strong>debugpy</strong> for debugging and <strong>watchmedo</strong> for reloading. My problem comes when trying to combine both of them: debugging + reloading in celery.</p>
  <p>EXTRA INFO:
  I've already a Flask app container where I can achieve this by only using <strong>debugpy</strong>. I don't need <strong>watchmedo</strong> nor <strong>inotify</strong> because flask already come with the <em>--reload</em> option. NICE! But this doesn't happen with celery since its old <em>--autoreload</em> option has been removed some time ago.</p>
  <p><strong>DEBUGGING:</strong></p>
  <p>To achieve the debugging I've made the following in my dockerfile:</p>
  <pre><code>CMD [&quot;python&quot;, &quot;-m&quot;, &quot;debugpy&quot;,  &quot;--wait-for-client&quot;,  &quot;--listen&quot;, &quot;0.0.0.0:9999&quot;, &quot;-m&quot;, &quot;celery&quot;, &quot;-A&quot;, &quot;celery_main&quot;, &quot;worker&quot;, &quot;-l&quot;, &quot;INFO&quot;, &quot;-n&quot;, &quot;worker&quot;, &quot;--concurrency=1&quot;]
  </code></pre>
  <p>That works fine but there is not reload on code changes.</p>
  <p><strong>RELOADING:</strong></p>
  <p>To achieve reloading I've made the following in my dockerfile.</p>
  <pre><code>CMD [&quot;watchmedo&quot; &quot;shell-command&quot; &quot;--patterns&quot; &quot;'*.py'&quot; &quot;--recursive&quot; &quot;--command='celery -A celery_main worker -l INFO -n worker --concurrency=1'&quot;]
  </code></pre>
  <p>That is also fine for reloading but I miss the debugging.</p>
  <p><strong>ATTEMPT: MIX</strong></p>
  <p>So I tried mixing both things but it doesn't seem to work. I just get nothing:</p>
  <pre><code>CMD [&quot;watchmedo&quot; &quot;shell-command&quot; &quot;--patterns&quot; &quot;'*.py'&quot; &quot;--recursive&quot; &quot;--command='python -m debugpy  --wait-for-client  --listen 0.0.0.0:5678 -m celery -A celery_main worker -l INFO -n worker --concurrency=1'&quot;]
  </code></pre>
  <p>BTW a problem that I guess will come if this eventually works, is that every time the code changes, the whole debugpy... command will be executed and that means that I must re-run the debugger on my IDE which is VSCODE.</p>
  <p>Any idea how to solve this issue(s) ??</p>