如何摆脱Python库代码中的无人值守断点?

时间:2016-07-19 16:35:34

标签: python visual-studio-debugging

每次我在Visual Studio 2015中开始Python代码的调试过程时,我都需要在Python库中的几行中经历很多停顿,这些停止在我的代码加载之前执行。例如,site.py的第143,147和184行有无人值守的断点(未在界面中显示)

def addpackage(sitedir, name, known_paths):
"""Process a .pth file within the site-packages directory:
   For each line in the file, either combine it with sitedir to a path
   and add that to known_paths, or execute it if it starts with 'import '.
"""
if known_paths is None:
    _init_pathinfo()
    reset = 1
else:
    reset = 0
fullname = os.path.join(sitedir, name)
try:
    f = open(fullname, "rU")  # <-- Line 143
except IOError:
    return
with f:
    for n, line in enumerate(f):  #  <-- Line 147
        if line.startswith("#"):
            continue
        try:
            if line.startswith(("import ", "import\t")):
                exec line
                continue
            line = line.rstrip()
            dir, dircase = makepath(sitedir, line)
            if not dircase in known_paths and os.path.exists(dir):
                sys.path.append(dir)
                known_paths.add(dircase)
        except Exception as err:
            print >>sys.stderr, "Error processing line {:d} of {}:\n".format(
                n+1, fullname)
            for record in traceback.format_exception(*sys.exc_info()):
                for line in record.splitlines():
                    print >>sys.stderr, '  '+line
            print >>sys.stderr, "\nRemainder of file ignored"
            break
if reset:
    known_paths = None
return known_paths

&lt; ...跳过...&gt;

def addsitedir(sitedir, known_paths=None):
        """Add 'sitedir' argument to sys.path if missing and handle .pth files in
        'sitedir'"""
        if known_paths is None:
            known_paths = _init_pathinfo()
            reset = 1
        else:
            reset = 0
        sitedir, sitedircase = makepath(sitedir)
        if not sitedircase in known_paths:
            sys.path.append(sitedir)        # Add path component
        try:
            names = os.listdir(sitedir)  # <-- Line 184, here it stops for a lot of times
        except os.error:
            return
        dotpth = os.extsep + "pth"
        names = [name for name in names if name.endswith(dotpth)]
        for name in sorted(names):
            addpackage(sitedir, name, known_paths)
        if reset:
            known_paths = None
        return known_paths

此外,与genericpath.py的第18行相同:

def exists(path):
    """Test whether a path exists.  Returns False for broken symbolic links"""
    try:
        os.stat(path)  #  <-- Line 18, breaks here very many times
    except os.error:
        return False
    return True

所有这些使得每个调试会话都非常缓慢。如何掩盖这些地方,以免它们再停止执行? 我在Windows 7 x64下使用Python 2.7.10和Visual Studio 2015。

1 个答案:

答案 0 :(得分:1)

在菜单中选择调试项,然后选择删除所有断点选项。键盘快捷键 Ctrl + Shift + F9 将完成相同的操作。