Debugging with pycharm, how to enter a project without entering django libraries

Think about this scenario:

I am debugging a Django project and I am reviewing the code (in and out). The debugger is sometimes included in Django libraries or other external libraries.

Does anyone know how to prevent the debugger from entering external code? Or at least the โ€œbigโ€ step to return the debugger to the project code?

+8
python debugging django pycharm
source share
2 answers

Does anyone know how to prevent the debugger from entering external code?

Yes, Dmitry Trofimov knows ;

(...) add modules that you do not want to trace to dict DONT_TRACE in <pycharm-distr>/helpers/pydev/pydevd.py
This is a hacker solution (...)

If you want this feature to be less hacked, you can vote for it by visiting the issue
PY-9101 Embed the Do Not Join Classes option for the Python debugger


Those using pdb may be interested to find out if there is such a function in pdb;

Starting in Python 3.1, the Pdb class has a new skip argument -

class pdb.Pdb(completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False)

The skip argument, if given, should be an iterable module of glob-style name templates. The debugger will not enter frames that occur in a module that matches one of these patterns. one

1 Regardless of whether the frame is considered to be the source in a particular module, defined by __name__ in global frames.

The example in the docs shows how to skip Django packages -

import pdb; pdb.Pdb(skip=['django.*']).set_trace()

+6
source share

Everything looks the same for the debugger, it cannot distinguish between your code or the Django code - all this is Python. Thus, it will run everything, however, if you want to stop it from drilling so low, you will have to start โ€œstep over" the lines of code, rather than "enter" them.

According to PyCharm docs, you will want to use F8 when you see a line of code that looks like it could be a gateway in the inside of Django. If you accidentally hit the Django source code, you can press Shift+F8 until you exit it.

0
source share

All Articles