breakpoints some hit some not hit in debug Django project

已回答

Hi, I'm using PyCharm Professional 2017.3.3 and macOS 10.12.6. And Python interpreter for my Django project is a docker-compose interpreter.

I set a few breakpoints in my Django project, they are all in views. Some breakpoints got hit very good, however some just missed.

Env variable PYCHARM_DEBUG is alse set to see the debug details. For the missed breakpoints, the thread created and killed in a very short time, see screenshots.

I'm confused, why does not PyCharm catch the breakpoints? Thanks.

missed breakpoint:

good breakpoint. I run it right after the missed breakpoint, you can see the massive output and I'm ok to debug.

0

Hi! Could you please provide a code sample for reproducing the bug? For example, a simplified version of your project?

0

Hi Elizabeth, do you know any possible reasons for breakpoints not hit in your experiences? My project is too big, hard to simply it.

good breakpoint:

import json
import random
import re
import time
import urllib2
from datetime import date, datetime
from django.http import HttpResponse
from django.shortcuts import render_to_response
# from django.db.models import Count
from common_libs import ipv4_re
from django.template import RequestContext
from django.views.decorators.cache import cache_page
from django.core.cache import cache as djcache

from lib.utils import nslookup, JsonResponse

from myproj.models import *
from myproj.pollers import get_lb_stats
from myproj.search import SearchManager, SEARCH_TYPE, SearchResult
from myproj.backends.base import ConfManager

from myproj.grid_data import (
prepare_grid_data, GRID_COLUMNS, SHOWN_COLUMNS, ATTRS_FLOATING_DISPLAY,
ATTRS_NODE, SORTERS, CHECK_BOXES, TRAFFIC_TITLE, PORT_ATTR, VLAN_ATTR)

from myproj.api.cms.cms_poller import CMSPoller
from django.conf import settings

def mainpage(request):

return_values = []
return_pie_data = []
return_conunter = []

# LB Type
lbtype = {}
total_lbnode_cnt = LBNode.objects.count()
counter = []

# *** breakpoint is here ***
for lb in LBNode.objects.all():
lbtype.setdefault(lb.lb_type, 0)
lbtype[lb.lb_type] += 1

for k, v in lbtype.items():
counter.append({
'cnt': v, 'name': LB_TYPES.getName(k), 'filter': 'lbnode.lb_type:%s' % k})
return_conunter.append({'counter': counter, 'width': 2})

# asset status
assetstatus = {}
counter = []
for e in LBNode.objects.values_list('assetstatus'):
assetstatus.setdefault(e[0], 0)
assetstatus[e[0]] += 1

for k in ASSET_STATUS:
counter.append({'cnt': assetstatus.get(k, 0),
'name': k.title(), 'filter': 'lbnode.assetstatus:%s' % k})
return_conunter.append({'counter': counter, 'width': 2})

# print return_conunter

return render_to_response(
'myproj/index.html', {
'total_lbnode_cnt': total_lbnode_cnt,
'return_conunter': return_conunter,
})

 

bad breakpoint:

from django.shortcuts import render_to_response
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.template import RequestContext
from django.core.context_processors import csrf
import json
import re
import nmap
import random
import socket
from IPy import IP
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from myproj.scripts.sync_vipsubnets import get_vipsubnets,C3_SUBNETS
from myproj.models import LB, VipSubnet
from django.contrib.auth.decorators import login_required
from api.cms.cms_poller import CMSPoller
from lib.config import PasswordManager
from lib.pssh import Connection
# TODO: include M2Crypt in requirements.txt and apt-get install swig in README.md
import M2Crypto
import logging
# to ignore "M2Crypto.SSL.Checker.WrongHost: Peer certificate subjectAltName does not match host"
from lib.utils import query_fqdn

M2Crypto.SSL.Connection.clientPostConnectionCheck = None
logger = logging.getLogger(__name__)

def change_lbms_password(request):

# *** breakpoint is here ***
c = {'user_is_allowed': True}
warning_content = []
user = 'lbms'

req_user = request.user
user_in_groups = [g.name for g in req_user.groups.all()]

if 'change_lbms_password' not in user_in_groups:
c['warning_content'] = "Not allowed. Please contact xxx@xxx.com."
c['user_is_allowed'] = False
return render_to_response("myproj/misc/change_lbms_password.html", c, context_instance=RequestContext(request))

if request.method == 'GET':
return render_to_response("myproj/misc/change_lbms_password.html", c, context_instance=RequestContext(request))

dd

 

0

vvoody Unfotunately it's difficult to investigate problem this way. Sometimes debugger behavior depends on the way the new process was created (for example: https://youtrack.jetbrains.com/issue/PY-14690) or on some Django-specific functions (https://youtrack.jetbrains.com/issue/PY-16650). Could you please try to simplify your big project?

0

请先登录再写评论。