5

I have my project properly configured to run manage.py in the right place, with the right settings.

picture of project configuration

I also have debug breakpoints set in a method that I know with certainty is being executed (I've put a print statement there and it executed as expected). The breakpoints are not disabled or conditional:

picture of breakpoints in code

When I hit the "Run in debug mode" button, using the above run configuration (I'm sure it's the same one because it's the only one I've configured for this project), this is the console output I get:

pydev debugger: process 38083 is connecting

Connected to pydev debugger (build 192.5728.105)
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
December 23, 2020 - 19:22:22
Django version 3.1.4, using settings 'FEArena.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

When I tried putting a breakpoint in manage.py, it worked as expected, triggering just when I hit the 'debug' button. However, after the app has started, when I use a REST client to trigger the above method, the one with breakpoints in it, the breakpoints do not trigger and the debugger doesn't start. I get a 200 OK response in my REST client, but PyCharm does not stop and execute the debugger at any point.

I looked at other answers that advised setting "Gevent compatible debugging" (which I don't have, because I'm using Community Edition), and I've tried deleting the .idea/ folder for the project, which also didn't fix the issue. I'm not sure what else could be causing this. I just want to debug my program.

My PyCharm version information is

PyCharm 2019.2 (Community Edition)
Build #PC-192.5728.105, built on July 23, 2019
Runtime version: 11.0.3+12-b304.10 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.7
GC: ParNew, ConcurrentMarkSweep
Memory: 4029M
Cores: 8
Registry: 
Non-Bundled Plugins: com.karateca.jstoolbox, mobi.hsz.idea.latex, net.seesharpsoft.intellij.plugins.csv, nl.rubensten.texifyidea, org.intellij.plugins.markdown

What could be causing the breakpoints to not be triggered, and how do I fix this? I need breakpoints to debug other parts of my program.

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53
  • try setting a breakpoint in manage.py and restart and see if it hits the breakpoint. – Albin Paul Dec 23 '20 at 19:33
  • This doesn't help you in debugging this way, but I suggest you to create and run test – 404pio Dec 23 '20 at 19:34
  • @AlbinPaul Putting a breakpoint in `manage.py` works as expected - it is triggered as soon as I hit the debug button. – Green Cloak Guy Dec 23 '20 at 19:34
  • 3
    I'd double check that you're hitting the functions you have the breakpoints in. A quick way to do that is to add a `print()` call to it. – schillingt Dec 23 '20 at 19:36
  • @schillingt As above, I'm 100% sure that the function with the breakpoint is getting hint, because of the REST call. But I did add a print call to the function, and that did execute and print to the console as expected, even though the breakpoint on it did not. – Green Cloak Guy Dec 23 '20 at 19:39
  • I tried to reproduce the error, but I didn't have any problem. [Here is my screenshot](https://i.stack.imgur.com/QCyKg.png). – JPG Jan 01 '21 at 18:50
  • as *schillingt* mentioned, double-check that your view is getting executed also check with other views and functions – JPG Jan 01 '21 at 18:53
  • Are you using `pytest` and/or `coverage` in your project? – trinchet Jan 03 '21 at 16:24
  • @trinchet I'm currently not using `pytest` or `coverage`, at least not deliberately. – Green Cloak Guy Jan 03 '21 at 18:04

4 Answers4

3

Are you running your server in a console by any chance? If thats the case try stopping the server runing in console and restart the one in PyCharm

SLDem
  • 2,065
  • 1
  • 8
  • 28
1

I was having a similar issue previously in PyCharm when I was invoking executor.submit. I had to insert a line requesting the results of the code in order to re-invoke the expected debugging behaviour. If your code is threaded, you may wish to start there.

future = executor.submit(control, channel) # spawn a function control(channel)
print(f'Future result is: {future.result()}') # new line I had to add to enable debugging

Edit: Adding the link to the thread that helped me with similar behaviour in PyCharm. concurrent.futures.ThreadPoolExecutor doesn't print errors

C. Cooney
  • 471
  • 5
  • 19
  • Beyond whatever Django does as a matter of course per HTTP request, I'm not deliberately invoking the threading, multiprocessing, or asyncio APIs, so I don't think there's anywhere in my code I could make this change. Is there? – Green Cloak Guy Jan 02 '21 at 19:28
  • I did some searching for another prior suggestion. Some had noted that changing PyCharm's variables loading policy may be helpful. Have you tried this? https://www.jetbrains.com/help/pycharm/variables-loading-policy.html – C. Cooney Jan 02 '21 at 20:03
  • This has more specific information on which option you may wish to choose. https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000409460-Debugging-not-running-on-PyCharm-for-my-Django-project – C. Cooney Jan 02 '21 at 20:04
  • Thanks for that suggestion, but after trying all three options, none of them seem to work. – Green Cloak Guy Jan 02 '21 at 20:37
  • If your goal is simply to re-enable debugging, this hack might work: https://www.valentinog.com/blog/pycharm-uvicorn/ I also note that PyCharm has a related bug issue reported, but this seems heavily dependent upon the code invocation approach which you have not highlighted as a potential cause. Wish I had the answer! Good luck..I know these are frustrating! – C. Cooney Jan 02 '21 at 21:51
1

My current working configuration is on this :

enter image description here

It does not have any script path or parameters.

When I click on the "Debug" green button, the command automatically launched is : /Users/.../virtualenv/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 55583 --file /Users/.../manage.py runserver 8000

What about yours ?

Henri
  • 780
  • 4
  • 10
  • Is this from the Professional Addition, where Django is built-in as its own run configuration type? This doesn't resemble my configuration page (using Pycharm Community Edition), as shown above, which is the vanilla python run configuration. That said, my command is `/Users/.../venv/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --save-signatures --qt-support=auto --client 127.0.0.1 --port 49472 --file /Users/.../manage.py runserver` – Green Cloak Guy Jan 06 '21 at 18:11
0

Hi I am writing this answer as I cannot comment because of my reputation no. By any chance, did you installed cython debugger toolkit that pycharm keeps on suggesting? If so, i have faced the same issue. The solution is to delete cython speedups somehow. You can follow this link to do that.

Basically you have to go to the directory called _pydevd_bundle and delete pydev*.so files. Now that requires root privilege. If you have that and you are able to delete them, then most likely it will work(provided you had installed cython debugger extension).

  • Thanks for the suggestion. I tried doing this, but unfortunately it didn't seem to have any effect, even after I restarted pycharm. – Green Cloak Guy Jan 07 '21 at 22:28